I have a simple math problem. I want to find a number in the range [2,N]
(excluding 1 and N from the divisors) with the largest sum of divisors. For example, for N = 100
the number with the highest sum of divisors between 2 and 100 is 96, which has the sum of all its divisors equal to 155.
I wrote the following program to show me the sum of that number's divisors but couldn't figure out how to get that number itself. How do I find and print that number?
int main(int argc, char const *argv[])
{
int N,
sum,
max=0;
scanf("%d", &N);
int i = 0,
d = 0;
for(i=2; i<=N; i++)
{
sum=0;
for(d = 2; d < i; d++)
{
if(i % d == 0)
{
sum += d;
}
}
if(sum > max)
{
max = sum;
}
}
printf("%d\n", max);
return 0;
}