0

当我尝试使用大整数时,我安装了 boost 库,但是当我尝试调试时,我得到常量太大的错误,而我认为 cpp_int 可以处理它吗?你能看看我的代码和错误吗?这是错误:

错误 C2177 常量太大 HW7 C:\Users\hmffa\source\repos\HW7\HW7.cpp 34
错误(活动) E0023 整数常量太大 HW7 C:\Users\hmffa\source\repos\HW7\HW7.cpp 34

#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace boost::multiprecision;


cpp_int Remainder(cpp_int base, cpp_int exp, cpp_int mod) {
    cpp_int r = 1;
    if (base < 0)
        base += mod;
    if ((base % mod) == 0)
        return r = 0;
    if (exp >= mod) {
        base = base % mod;
        exp = exp % (mod - 1);
    }
    while (exp > 0) {
        if (exp % 2 == 1) {
            r = (r * base) % mod;
        }
        exp = exp >> 1;
        base = (base * base) % mod;
    }
    return r;
}



int main()
{
    int B[3] = { 2,3,5 }, C[3] = { 0,0,0 };
    cpp_int input = 2, pow = input, exp = 0, powerInput;
    cpp_int p= 30903154482632612361920641803533;
    int i = 0;
    while (i < 3) {
        exp++;
        powerInput = Remainder(input, exp, p);
        while (powerInput % B[0] == 0)
            C[0]++;
        while (powerInput % B[1] == 0)
            C[1]++;
        while (powerInput % B[2] == 0)
            C[2]++;
        for (int j = 0; j < 2; j++) {
            if (C[j] != 0)
                cout << C[j] << " ";
        }
        cout << endl;
        if (C[0] != 0 || C[1] != 0 || C[2] != 0)
            i++;
    }

}
4

1 回答 1

2

改变

cpp_int p= 30903154482632612361920641803533;

cpp_int p{"30903154482632612361920641803533"};
于 2020-05-16T17:30:43.297 回答