Perfect numbers calculator seems to freeze after some time

Hello everyone, I'm new here as well as in C++ and programming in general.
I have a program which finds perfect number from 1 up to the number I give it.
It finds the first 4 numbers instantly but after 16+ hours it still hasn't found the next one. Is the program stuck maybe or it just takes so long?

Here's the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <ctime>

using namespace std;

const time_t ctt = time(0);

int main(void)
{ 
 //variables
 long long int i,j,sumOfFactors,endnum;
 
 cout << "I will check from 1 up to which number?" << endl;
 cin >> endnum;

 cout << endl << "These are the perfect numbers from " << "1 to " << endnum << endl << endl;

 //check numbers from 1-1000
 for (i = 1; i <= endnum; i++)
 {
  sumOfFactors = 0;

  //look for the factors of a number
  for (j = 1; j < i; j++)
  {
   //check for factors and add them up
   if (0 == (i%j))
   {
    sumOfFactors += j;
   }
  }

  //if perfect number, print
  if (sumOfFactors == i)
  {
   cout << "Perfect Number: " << i << " Time found: " << asctime(localtime(&ctt)) << endl;
  }
 }
   
 getchar();

 return 0;
}


EDIT: The number which i gave it to search up to is 100000000000
Last edited on
Topic archived. No new replies allowed.