A single natural number n is read from standard input. Among the natural numbers less than n, find the one whose sum of divisors is the largest. In calculating the sum of the divisors of a given number, the number itself should not be taken into account.
int n;
cin>>n;
int max=0;
for (int i=n-1; i>0; i--) {
int sum=0;
if (n%i==0) {
sum+=n;
}
if (max<sum) {
max=sum;
}
}
cout<<max;
Heres my attempt but its apparantley wrong, can someone tell me why it is wrong and how to correct it?