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?
#include <iostream>
#include <ctime>
usingnamespace std;
const time_t ctt = time(0);
int main(void)
{
//variables
longlongint 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