#include #include #include static int const ifactors[17]= { 11,41,101,251,271,3541,5051,9091, 21401,25601,27961,60101,7019801, 0,0,0,0 /* too large */ }; static char const *factors[17]= { "11","41","101","251","271","3541","5051","9091", "21401","25601","27961","60101","7019801", "182521213001","14103673319201","78875943472201","1680588011350901" }; /* remember there are 2 threes too */ static mpz_t gfactors[3][1<<17]; static unsigned int red85085[3][1<<17]; /* Could sort them? Yeah - why not! */ static int indices[3<<17]; int derefcmp(const void* pa, const void* pb) { int i1=*(const int*)pa; int i2=*(const int*)pb; return mpz_cmp(gfactors[i1&3][i1>>2], gfactors[i2&3][i2>>2]); } int main(int argc, char**argv) { int threes; int k; mpz_t gq, gt; /* temporary for q, and the power therefrom */ /* d=divisors(10^100-1); */ for(threes=0; threes<=2;++threes) { static const int threepow[3]={1,3,9}; int family; mpz_init_set_ui(gfactors[threes][0], threepow[threes]); indices[threes<<17]=threes; for(family=0; family<17; ++family) { int familybase=1<>2; /* throw away ones done at a lower k */ if((n32 || index>4) { continue; } /* don't risk skipping the really small ones */ } /* p=gfactors[n3][n] */ mpz_mul_ui(gq, gfactors[n3][n], 2*k); mpz_add_ui(gq, gq, 1); if(mpz_probab_prime_p(gq, 1)) { /* if(lift(Mod(10,q)^p+1)==0&&ispseudoprime(q),print(q)))) */ mpz_set_ui(gt, 10); mpz_powm(gt, gt, gfactors[n3][n], gq); mpz_add_ui(gt, gt, 1); if(mpz_cmp(gt, gq)==0) /* power+1 == q */ { mpz_out_str(stdout, 10, gq); printf("\n"); } } } } return 0; }