// this is a program to generate the terms > 5 of A154587 // it is not an example of good programming. // this program uses primegen library by D.J.Bernstein, which // provides a quite fast and easy to use sieve that generates // primes up to 10^15. // here unsigned long long int are assumed to be 64-bit integers // the program is compiled and run on a 64-bit linux machine // compiled with -std=c99 #include #include #include // Here I define a function to print 128-bit integers, // since there is not such a function for gcc // 128-bit integers are an extension provided by gcc #define QLong __uint128_t #define DD (10000000000000000000LLU) char s_t[64]; char *toS(QLong x) { if (x=Lim) { printf(">> %llu g (%s)\n",curCo/STP,toS(sumC)); Lim += STP; // if LastP is larger than 9.9*10^14 I exit if (LastP>990000000000000LLU) return 0; } // if the two sums are equal I have a new term, // I print it and I save it on file. if (sumP==sumC) { FILE *f = fopen("A154587.txt","a"); fprintf(f,"%s\n",toS(sumP)); fclose(f); printf("%s\n",toS(sumP)); // I update the two sums sumP += (LastP=primegen_next(&pgprim)); sumC += NextComp(); } // while the sum of primes is smaller than the sum // of non-primes I add primes while (sumPsumC) sumC += NextComp(); } return 0; }