我有这个程序需要处理大数字来将数字分解为质数..就像RSA分解挑战一样。
我在带有素数的txt文件中得到了这个列表。这是我用来制作该列表的一段代码:
int export_list (int lim = 50)
{
int last_in_txt = 0;
{
ifstream infile ("Primes.txt");
int k;
while(infile >> k)
{ last_in_txt = k; }
}
// Now last_in_txt is assigned properly, and Primes.txt is closed
cout << "\nLast number in \"Primes.txt\": " << last_in_txt << endl << endl;
cout << "Press <Enter> to start appending primes... ";
cin.get();
cout << "\nAppend started:\n";
last_in_txt++;
ofstream file ("Primes.txt" , ios::app);
int x, counter;
if (file.is_open()) // if it opens correctly
{
for (x = last_in_txt , counter = 0 ; counter < lim ; x++ , counter++)
{
if (check_prime (x)) // returns 1 when x is prime, returns 0 when not
{
cout << "Appending " << x << "\t\t" << "Estimated time remaining: " << (lim - counter) / 1000 <<endl;
file << x << " ";
}
}
cout << "Done!" << endl << endl << pressenter;
cin.get();
}
else
{
cout << "Unable to open file" << endl << pressenter;
cin.get();
}
return(0);
}
问题是,当我发现这个txt文件包含大于32位的数字时,它不会处理它们...... last_in_txt
变量将始终存储txt文件中的最后一个数字,即不超过32位...