// compiler avec g++ -o gmp_integer_example.exe gmp_integer_example.cpp -O3 -lgmp #include #include #include #include using namespace std; // fonction qui transforme une chaine de la forme 1289347884 // en 1_289_347_884 string separateur(const string& input, char separator = '_') { string result; int count = 0; // Iterate the string in reverse order for (int i = input.size() - 1; i >= 0; --i) { result.push_back(input[i]); count++; // Insert separator every 3 digits, but not after the last group if (count == 3 && i != 0) { result.push_back(separator); count = 0; } } // Reverse the result string back to correct order std::reverse(result.begin(), result.end()); return result; } ostream& operator<<(ostream& out, mpz_t& z) { char* str = mpz_get_str(nullptr, 10, z); out << separateur( str ); // Output the string to the stream free(str); return out; } int main() { mpz_t a, b; mpz_init(a); mpz_init(b); // calculer 2^64 en multipliant a=1 par b=2 64 fois mpz_set_ui(a, 1); mpz_set_ui(b, 2); for (int i = 1; i <= 64; ++i) { mpz_mul(a, a, b); } cout << "2^64 = " << a << endl; // utiliser la fonction puissance pour calculer 2^128 mpz_ui_pow_ui(a, 2, 128); cout << "2^128 = " << a << endl; // utiliser la fonction puissance pour calculer 2^32 mpz_ui_pow_ui(a, 2, 32); cout << "2^32 = " << a << endl; mpz_clear(a); mpz_clear(b); return EXIT_SUCCESS; }