C++ C++;VS2012处理大于32位的数字
我有一个程序,需要处理大量的数字,才能将一个数字分解成素数。。就像RSA分解挑战一样 我在一个包含素数的txt文件中得到了这个列表。这是我用来制作该列表的代码:C++ C++;VS2012处理大于32位的数字,c++,visual-studio-2012,C++,Visual Studio 2012,我有一个程序,需要处理大量的数字,才能将一个数字分解成素数。。就像RSA分解挑战一样 我在一个包含素数的txt文件中得到了这个列表。这是我用来制作该列表的代码: int export_list (int lim = 50) { int last_in_txt = 0; { ifstream infile ("Primes.txt"); int k; while(infile >> k) { last_in
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);
}
int导出列表(int lim=50)
{
int last_in_txt=0;
{
ifstream infle(“Primes.txt”);
int k;
而(填充>>k)
{last_in_txt=k;}
}
//现在,正确分配了_txt中的最后一个_,Primes.txt被关闭
cout如果一个64位整数就足够了,请使用int64。如果需要更大的数字,请检查以下问题:它比64位数字大吗?数字的大小有任何限制吗?只需使用long-long来让程序忙碌多年。@MerickOWA它们是这样的3797522793693673922808872755445627854565536638199好的,一年多了s、 答案是42。一定要避免在这些问题上浪费精力: