Good day everyone.
The task is to factorize a long number > 10 digits. Program works OK until I input a >= 12 digit number. What can be the reason? (Not enough memory?)
#include "LinkedList.h"
void main ( int argc, char *argv[] )
{
longlong Input = 0;
printf_s ( "%s\n", "Please input the number" );
//scanf_s ( "%d", & Input );
cin >> Input;
longlong Test = Input;
longlong Number = 1;
Prime * First = new Prime ( Number );
Prime * pPrime = new Prime (0);
while (1)
{
++Number; //Number = 2
/*cout <<"Number is\t"<< Number << endl;
cout <<"Input is\t"<< Input << endl;*/
if ( isPrime ( Number ) )
{
while ( Input % Number == 0 )
{
pPrime = new Prime ( Number );
First -> insert ( pPrime );
Input = Input / Number;
}
}
if ( Test == ( First -> multiply() ) ) break;
}
First -> display();
cout << "Verification" << endl;
cout << First -> multiply() << endl;
system ("PAUSE");
}
It works perfectly fine for me, I tried 15 digits. I don't know how accurate it is, but it seems to be working correctly.
Edit: If you believe you're running out of memory, it isn't much more, but you could try unsigned long long as long as you don't need negative numbers.
Edit: Or even try a long long double...I believe that's the correct datatype, even a long double is very large.