get perfect number and show them like expression 6 = 1 + 2 + 3.
#include <iostream>
using namespace std;
int main ()
{
int sum;
for ( int i = 2; i <= 10000; i++ ){
sum = 0;
for ( int j = 1; j < i ; j++ ){
if ( i % j == 0 ){
sum += j;
}
}
if ( i == sum ){
cout << i << " = ";
for ( int j = 1; j < sum; j++ ){
int sumtest = 0;
sumtest += j;
if (sum % j == 0){
if ( sumtest == sum - j ){
cout << j << endl;
}
else {
cout << j << " + ";
}
}
}
cout << endl;
}
}
return 0;
}
and the following picture is my getting.