This is my code. I am trying to multiply two very large numbers (maximum digits can be 100000) and the present the result as modulo of 10^9 + 7
#include <bits/stdc++.h>
#include <gmp.h>
#include <gmpxx.h>
using namespace std;
long long int rem = 1000000007;
int main() {
mpz_class A, B, res;
cin>>A>>B;
res = 1;
for(int i=1; i<=B; i++)
res = res*A;
res = res % rem;
cout<<res<<"\n";
return 0;
}
But I get this error when I compile it:
error: ambiguous overload for ‘operator%’ (operand types are ‘mpz_class {aka __gmp_expr<__mpz_struct [1], __mpz_struct [1]>}’ and ‘long long int’)
res = res % rem;
Here A and B can be as large as below respectively:
74543987529435983745230948023948 6498573497543987543985743989120393097595572309482304
EDIT:
/*Header files same as prev*/
mpz_class rem (1000000007);
int main() {
mpz_class A, B, res;
cin>>A>>B;
res = A ^ B; // Using "^" to denote exponentiation since we have used
res = res % rem; // "+" and "%" instead of mpz_sum and mpz_mod functions
cout<<res<<"\n";
return 0;
}
The ERROR message is:
/ccqd5nye.o: In function `__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::~__gmp_expr()':
/usr/include/gmpxx.h:1523: undefined reference to `__gmpz_clear'
/ccqd5nye.o: In function `__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr()':
/usr/include/gmpxx.h:1488: undefined reference to `__gmpz_init'
/usr/include/gmpxx.h:1488: undefined reference to `__gmpz_init'
/usr/include/gmpxx.h:1488: undefined reference to `__gmpz_init'
/ccqd5nye.o: In function `std::istream& operator>><__mpz_struct [1]>(std::istream&, __gmp_expr<__mpz_struct [1], __mpz_struct [1]>&)':
/usr/include/gmpxx.h:2039: undefined reference to `operator>>(std::istream&, __mpz_struct*)'
/usr/include/gmpxx.h:2039: undefined reference to `operator>>(std::istream&, __mpz_struct*)'
/ccqd5nye.o: In function `__gmp_binary_xor::eval(__mpz_struct*, __mpz_struct const*, __mpz_struct const*)':
/usr/include/gmpxx.h:846: undefined reference to `__gmpz_xor'
/ccqd5nye.o: In function `__gmp_binary_modulus::eval(__mpz_struct*, __mpz_struct const*, __mpz_struct const*)':
/usr/include/gmpxx.h:763: undefined reference to `__gmpz_tdiv_r'
/ccqd5nye.o: In function `std::ostream& operator<< <__mpz_struct [1], __mpz_struct [1]>(std::ostream&, __gmp_expr<__mpz_struct [1], __mpz_struct [1]> const&)':
/usr/include/gmpxx.h:2033: undefined reference to `operator<<(std::ostream&, __mpz_struct const*)'
/ccqd5nye.o: In function `__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::~__gmp_expr()':
/usr/include/gmpxx.h:1523: undefined reference to `__gmpz_clear'
/usr/include/gmpxx.h:1523: undefined reference to `__gmpz_clear'
/usr/include/gmpxx.h:1523: undefined reference to `__gmpz_clear'
/usr/include/gmpxx.h:1523: undefined reference to `__gmpz_clear'
/usr/include/gmpxx.h:1523: undefined reference to `__gmpz_clear'
/ccqd5nye.o:/usr/include/gmpxx.h:1523: more undefined references to `__gmpz_clear' follow
/ccqd5nye.o: In function `__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::init_ui(unsigned long)':
/usr/include/gmpxx.h:1465: undefined reference to `__gmpz_init_set_ui'