### Power Function at GMP Library

I recently downloaded GMP Library for big num. Everything worked fine but when i'm trying to use the pow(2, x) where the x is a mpz_class it wont work.

And i'm not sure about the gmp function of mpq_ui_pow_ui or mpq str .
any idea how can i do a 2 to the power of big num?
2 to the power of a big num is going to be a VERY big num! Think about 2 to the power of LONG_MAX+1. Are you sure that's what you need? How is the result used?

In any case, GMP doesn't raise anything to bignum exponents: it can raise unsigned long to unsigned long and store the result in a bignum (mpz_ui_pow_ui), it can raise a bignum to an unsigned long power (mpz_pow_ui), or it can raise a bignum to a bignum power MOD another bignum (mpz_powm).

And yes, neither power nor arithmetic left shift are available for mpz_class objects, and yes you have to call the C interface:

 123456789 #include #include int main() { mpz_class r; mpz_ui_pow_ui (r.get_mpz_t(), 2, 123); std::cout << 2 << "^" << 123 << " = " << r << '\n'; }

 2^123 = 10633823966279326983230456482242756608 
Last edited on
i'm actually trying to make a program that can find the largest prime number.
but i need to divide the mpz_class with 2 int and it shows:
ambigous overload for 'operator=' in '.... =(..../...)'

here's the code
 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 #include #include #include #include #include #include #include using namespace std; typedef mpz_class a; int main() { SetConsoleTitle(L"Prime Number Finder"); clock_t start; unsigned long long isPrime, sqrtPrime, addPrime = 3, ansPrime,dPrime = 0.0; a dans; cout << "Please insert a number to test as prime number\n"; cout << "Insert a power of 2 \n"; cin >> isPrime ; mpz_ui_pow_ui(dans.get_mpz_t(), 2, isPrime); // isPrime = pow(2 ,isPrime) - 1; if(isPrime==0){ cout << "Please insert a valid number !!! \a \n "; } start = clock(); sqrtPrime = sqrt(isPrime); if(addPrime
 i'm actually trying to make a program that can find the largest prime number.
Let P(n) be the set of all positive prime numbers <=n. Note that P(n) is finite. Let
m = 1 + \product_{i \in P(n)} i
m is indivisible by all i in P(n), therefore (fundamental theorem of algebra) there exists a prime number larger than n. In other words, for any natural number, there exists a prime number that is larger than it. All positive prime numbers are natural, therefore for any prime number there exists at least one prime number that is larger. Therefore, no prime number is the largest.
Last edited on
not the question.. :D
any help?
We cannot help you find the largest prime number because it does not exist.
well, you 2 guys....
how bout when i enter a number and it will become 2^(the number)
and check if the number is a prime or not.?
Here you go :)

 12345678910 #include #include int main() { std::string x; std::cout << "Enter the number to raise two to the power of: "; std::cin >> x; std::cout << " 2^" << x << " is NOT prime."; }
Last edited on
2^x and -1