Search code examples
c++boostboost-multiprecision

Getting constant too big error while using boost library (cpp_int)


As I am trying to work with big integers I installed boost library but when I try to debug I get constant too big error while I think cpp_int can handle it right? could you please take look at my code and error? here is the error:

Error C2177 constant too big HW7 C:\Users\hmffa\source\repos\HW7\HW7.cpp 34
Error (active) E0023 integer constant is too large 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++;
    }

}

Solution

  • Change

    cpp_int p= 30903154482632612361920641803533;
    

    to

    cpp_int p{"30903154482632612361920641803533"};