int main(int argc, char* argv[]) { unsigned int max_pd_prime = 0; sieve_t sieve = prime_sieve(LIMIT); for(int i = 0; i < sieve.num; i++) { char digits[64]; memset(digits, '\0', 64); int len = sprintf(digits, "%u", sieve.primes[i]); bool is_pan = true; for(int c = 1; c <= len; c++) { if(substr_count(digits, len, c + 48) != 1) { is_pan = false; break; } } // primes are always increasing so no need to check if(is_pan) { max_pd_prime = sieve.primes[i]; } } printf("%u", max_pd_prime); return 0; }
void test() { vector<int> res, empty; res = prime_sieve(1); assert_deep_equal(empty, res); res = prime_sieve(2); empty.push_back(2); assert_deep_equal(empty, res); res = prime_sieve(3); empty.push_back(3); assert_deep_equal(empty, res); res = prime_sieve(4); assert_deep_equal(empty, res); res = prime_sieve(5); empty.push_back(5); assert_deep_equal(empty, res); res = prime_sieve(32); empty.push_back(7); empty.push_back(11); empty.push_back(13); empty.push_back(17); empty.push_back(19); empty.push_back(23); empty.push_back(29); empty.push_back(31); assert_deep_equal(empty, res); }
int main(int argc, char **argv) { unsigned long i, n; if (argc > 1) n = atoll(argv[1]); if (n == 0) n = 120; char *primes = prime_sieve(n); for (i=2; i <= n; i+=1) { if (primes[i] == 0) printf("%lu\n", i); } free(primes); return 0; }
int main(int argc, char* argv[]) { if(argc < 2) { printf("Please provide a number as a single argument.\n"); return 1; } int n = atoi(argv[1]); int* primes = (int *)malloc( sizeof(int)*n ); assert(primes != 0); init_array(primes, n); int num_prime = prime_sieve(primes, n); printf("%ld Primes less than %ld.\n", (long)num_prime, (long)n); print_primes(primes, n, num_prime); free(primes); return 0; }
int main(void) { char *sieve = prime_sieve(N); unsigned *primes = malloc(sizeof(unsigned) * N); unsigned i, j = 0; for (i = 0; i < N; i++) { if (!sieve[i]) { primes[j++] = i; } } primes[j] = 0; for (i = 3; i < N; i += 2) { if (!sieve[i]) { /* skip if i is prime */ continue; } for (j = 0; primes[j]; j++) { unsigned s; if (primes[j] > i) { printf("%u\n", i); goto FINISH; } s = (i - primes[j])/2; if (is_square(s)) { break; } } } FINISH: free(sieve); free(primes); return 0; }
int main(int argc, char *argv[]) { const int stage=atoi(argv[1]); long down=(long)(stage-1)*1000000; long up=(long)stage*1000000; // blocksize = 1000000 (1 million) printf("Primes %ld-%ld\n",down,up); clock_t begin,end; double times; begin=clock(); // This is the list of discriminants we want to find counterexamples for long D_list[10]={1073741783,4294967291,8589934583,17179869143,34359738319,68719476731,137438953447,274877906899,549755813723,1099511627563}; int h_list[10]={22991,34805,107849,136023,86757,98601,162855,114227,220527,176451}; // The upper bound of these discriminants is D_max long D_max=pow(2,40), D, p; // The upper bound of class numbers for these discriminants is h_max int h_max = h_upper_bound(-D_max); int temp=1, h, order; int *factors_of_h=NULL; factors_of_h = (int *) realloc(factors_of_h, 17* sizeof(int)); char aac_file[100]; // Use prime sieve to find all primes less than D_root, D_root>sqrt(up) int* primes; long D_root=10000000; primes = (int *) malloc(((int) (1.25506 * D_root / log(D_root))) * sizeof(int)); prime_sieve(D_root, primes); primes = (int *) realloc(primes, (2 + primes[0]) * sizeof(int)); for(int count=0;count<10;count++) { D=D_list[count]; h=h_list[count]; // Save the counterexamples in the file ./AAC/D/D_stage sprintf(aac_file,"./AAC/%ld/%ld_%d",D,D,stage); FILE* wf=fopen(aac_file,"w"); for(p=down+1;;p++) { if(p>up) break; if(isprime(p,primes)==1) { if(legendre_symbol(-D,p)==1) { if(h==1) order=1; else { temp=h;int count=1; factors_of_h[0]=0; for(int s=1;primes[s]<=h_max;s++) { if(temp%primes[s]==0) { factors_of_h[count]=primes[s]; count++; factors_of_h[0]=factors_of_h[0]+1; while(temp%primes[s]==0) temp=temp/primes[s]; } if(temp<=1) break; } order=order_mpz(D,p,h,factors_of_h); } aac(D,p,order,wf); } } } // run out the primes fclose(wf); } // count loop ends free(factors_of_h); free(primes); end=clock(); times=(double)(end-begin)/CLOCKS_PER_SEC; printf("stage %d:%lf seconds\n",stage,times); return 0; }