使用boost库(cpp_int)时获取常量时出错
Getting constant too big error while using boost library (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"};
相关文章:
- constexpr 函数获取常量字符*
- 如何在 c++ stl 中获取列表中被推回的元素的地址,在常量时间内?
- C++ 获取函数在常量引用中按值返回的结果
- 如何在常量计算表达式中获取编译时错误?
- C++ 获取向量中常量字符* [ ] 的长度
- 使用boost库(cpp_int)时获取常量时出错
- 获取模板以匹配常量 T* 和非常量 T* 的不同序列
- 你能安全地从字符串的 c_str() 常量字符*中获取指向字符串的指针吗?
- 获取对常量规范重载的成员函数的引用
- 如何从模板获取常量矢量元素的引用
- 使用 declval 获取非常量迭代器
- 我们可以获取子字符串的常量引用吗?
- 在 c++ 中获取常量字符 * 长度的最佳方法
- 在常量引用获取器上读取写入互斥锁(使用 Qt)
- 如何从对象中获取公共常量?
- 如何获取指向字符数组中第一个字符的常量指针
- 从指针检索字符串时获取常量空行输出
- 如何从 QString 获取常量字符 *
- 如何在退出 switch() 后获取常量表达式
- 从 GLSL 着色器获取常量