bool Isprime(const LL &n) { if(n<MAXPRIME) { return !iscom[(int)n]; } for(int i=0;i<12;++i) { if(n==prime[i]) return true; if(n%prime[i]==0) return false; } for(int i=0;i<12;++i) if(!Miller(prime[i],n)) return false; return true; }
/* * It is a function that generates random prime numbers * input: prime (mpz_t) for retrieving the prime and bitUsed for determining the bits size * output: mpz_t prime will be captured in host if parameter of main is void, e.g. main(void) */ void generatePrime(mpz_t prime, int bitUsed){ int check; mpz_t rop; unsigned long int seed; gmp_randstate_t state; srand(time(NULL)); seed = rand(); gmp_randinit_default (state); gmp_randseed_ui(state, seed); mpz_init(rop); int cond = 1; for(check = 0; check != 1;) { switch(cond){ case 1: mpz_urandomb(rop, state, bitUsed); printf("."); if(CheckOdd(rop) == 1){ cond = 2; }else{ cond = 1; } break; case 2: if(TrialDivision(rop) == 1){ cond = 3; }else{ cond = 1; } break; case 3: if(Miller(rop,10) == 1){ check = 1; }else{ cond = 1; } break; } } printf("\n"); mpz_set(prime, rop); gmp_randclear(state); mpz_clear(rop); return 0; }