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:
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 '.... =(..../...)'
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.
#include <iostream>
#include <string>
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.";
}