Ok ,like you said I mechanickly created each of the pruposed function of my C++
code
but i need to cut it down so for each number it will print the pair with
the smallest number
for 54(showes now):
24=12+12
30=12+18
32=12+20
36=12+24
36=18+18
38=18+20
40=20+20
42=12+30
42=18+24
44=20+24
48=12+36
48=18+30
48=24+24
50=20+30
52=12+40
54=12+42
54=18+36
54=24+30
i need it to show for 54(for each number i need only one sum of the smallest number pair):
54=12+42
52=12+40
50=20+30
48=12+36
44=20+24
42=12+30
40=20+20
38=18+20
36=12+24
24=12+12
30=12+18
32=12+20
Code:
#include<stdio.h>
int sum_of_divisors(int n) {
int result=1;
int k=2;
for(k=2;k*k<=n;++k) {
if(n%k==0) {
int sum_of_powers=1, power=1;
do {
power*=k;
sum_of_powers+=power;
n/=k;
} while(n%k==0);
result*=sum_of_powers;
}
}
if (n > 1)
return (n + 1) * result;
else
return result;
}
int is_abundant(int tndex) {
int jndex,sum;
int flag_1;
flag_1=0;
sum=0;
for(jndex=1;jndex<tndex;jndex++){//start abbondence check for first num (tndex)
if (tndex%jndex==0){
sum=sum+jndex;
}
if (tndex<sum){
flag_1=1;
}
}//end abbondence check for first num
return flag_1;
}
void print_if_sum_of_abundants(int n) {
int i;
for( i=1;i*2<=n;++i) {
if(is_abundant(i)&&is_abundant(n-i)) {
printf("%d=%d+%d\n",n,i,(n-i));
}
}
}
int main() {
int limit = 54;
int i;
for(i=1;i<=limit;++i) {
print_if_sum_of_abundants(i);
}
return 0;
}