0
[SOLVED] My code can't find the 5th perfect numbers
It's only found the 4th perfect number and my code did't run anymore. #include <iostream> using namespace std; int main() { long long int n,x,sum; for (n=1;n<=100000000;n++){ sum=0; for(x=1;x<n;x++){ if(n%x==0){sum+=x;} }if(sum==n) {cout<<n<<endl;} } return 0; }
3 odpowiedzi
+ 8
Your loop(s) is/are causing a timeout on the server for certain value range maybe 🤷♂️. Your code is given a certain amount of time to execute once it reaches the server. If it doesn't complete within that allotted time period, it times out.
Try this same program on any compiler other than Sololearn and check the result.
+ 4
Perfect numbers:
6,
28,
496,
8128,
33550336,
8589869056,
137438691328
https://www.sololearn.com/learn/4646/?ref=app
+ 1
Oh tks u so much man