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; }

30th Oct 2019, 3:48 PM
Phạm Đức
Phạm Đức - avatar
3 ответов
+ 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.
30th Oct 2019, 4:16 PM
Nova
Nova - avatar
+ 4
Perfect numbers: 6, 28, 496, 8128, 33550336, 8589869056, 137438691328 https://www.sololearn.com/learn/4646/?ref=app
30th Oct 2019, 4:12 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 1
Oh tks u so much man
30th Oct 2019, 4:17 PM
Phạm Đức
Phạm Đức - avatar