GNU MP: Cannot allocate memory (size=4080472064)

george pv pvgeorgepv at yahoo.com
Thu Apr 11 19:12:51 CEST 2013


Hi all,
I am a newbie to programing, trying to do a Fermat primality test of a 100000000 digit number. The code is aborted when I put the line for MPZ_POWM. With small numbers the code is working fine. 
 
The execution stops with the message: GNU MP: Cannot allocate memory (size=4080472064)
Aborted (core dumped) 
The part of the code is given below.
 //Fermat Primality test of 100000000 digit number
#include <gmpxx.h>
#include <iostream>
using namespace std;
int
     main (void)
     {
     mpz_t a, b, c, e;
     mpz_init(a);
     mpz_init(b);
     mpz_init(c);
     mpz_init(e);
     mpz_set_ui(e, 10); // e=10
     mpz_pow_ui(a, e, 99999999); //a=10^99999999
     mpz_set(b, a); //b=a
     mpz_add_ui(a, a, 1); //a=a+1
     mpz_set_ui(e, 2);
     mpz_powm(c, e, b, a); //c=2^b mod a, Fermat test
.........................
     cout << "\n finished!";
     return 0;
     }
 
Any help is appreciated. 
Thanks in advance
PV George 


More information about the gmp-discuss mailing list