-1

我有这个程序需要处理大量数字以将数字分解为素数。就像 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变量将始终存储不大于 32 位的 txt 文件中的最后一个数字......

4

1 回答 1

1

如果 64 位整数就足够了,请使用 int64_t。如果您需要更大的数字,请检查以下问题:Bigint (bigbit) library

于 2013-02-07T00:50:30.810 回答