使用boost库(cpp_int)时获取常量时出错



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

错误C2177常量过大HW7 C:\Users\hmffa\source\repos\HW7\HW7.cpp 34
错误(活动)E0023整数常量过大工作流7 C:\Users\hmffa\ssource\repos\WW7\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++;
}
}

更改

cpp_int p= 30903154482632612361920641803533;

cpp_int p{"30903154482632612361920641803533"};

最新更新