int main() { int i; long long count = 0; const int limit = 1000001; int * Primes = (int*) malloc(limit*sizeof(int)); int * OrderedPrimes = (int *) malloc(limit*sizeof(int)); SieveOfEratosthenes(Primes, limit); memcpy(OrderedPrimes, Primes, limit*sizeof(int)); OrderPrimeList(OrderedPrimes, limit); for(i = 2; i < limit; i++) { if(isPrime(i, Primes)) count += i-1; else count += totient(i, OrderedPrimes); } printf("%lld\n", count); free(Primes); free(OrderedPrimes); return 0; }
// Driver Program to test above function int main() { int n = 30; printf("Following are the prime numbers below %d\n", n); SieveOfEratosthenes(n); return 0; }
// Driver Program to test above function int main() { int n = sqrt(99999); FILE* fp=fopen("PrimeGenerator.txt","w"); fprintf(fp,"{"); SieveOfEratosthenes(n,fp); fprintf(fp,"}"); return 0; }
int main (int argc, char *argv[]) { std::ifstream input_file(argv[1]); // open the input file unsigned long long seiveRange = 4967295; bool array[seiveRange + 1]; SieveOfEratosthenes(array, seiveRange + 1); unsigned long long N; while(input_file) { input_file >> N; printf("2"); for (unsigned long long i = 3; i < N; i++) if (array[i]) printf(",%llu",i); printf("\n"); } }
int main() { int n, i, j, k, count, c, x, t, test, num; int P[5133]; SieveOfEratosthenes(P,50000); long long s, e; scanf("%d", &test); for (k = 0; k < test; k++) { s = 1; scanf("%d", &n); for(i = 0; P[i] <= n && i < 5133; i++) { num = n; e = 0; while(num) { e = e + num/P[i]; num = num/P[i]; } s = (s*(e+1))%1000000007; } printf("%lld\n", s); } return 0; }
int main() { int cnt = 0; char ans[4]; SieveOfEratosthenes(); for(int i = 0; i < MAXN; ++i) { if(!NotPrime[i]) { Prime[cnt++] = i; } } cnt = 0; for(int i = 0; i < 15; ++i) { printf("%d\n", Prime[i]); ++cnt; fflush(stdout); scanf("%s", ans); if(ans[0] == 'y') { for(int j = i; j < 15; ++j) { if(Prime[i]*Prime[j] < 100) { printf("%d\n", Prime[i]*Prime[j]); ++cnt; fflush(stdout); scanf("%s", ans); if(ans[0] == 'y') { puts("composite"); return 0; } } } puts("prime"); break; } } puts("prime"); return 0; }
int main() { SieveOfEratosthenes(Primes, 1000); srand(time(NULL)); char croaks[] = "PPPPNNPPPNPPNPN"; RunSimulations(); bignum numerator; bigset(numerator, 119); bignum denominator; bigset(denominator, 300); bignum temp1; bigset(temp1, 190); bignum temp2; bigset(temp2, 405); bignum temp3; biginit(temp3); bignum temp4; biginit(temp4); bignum temp5; biginit(temp5); int i; for(i = 1; i < 15; i++) { bigmulint(temp3,bigadd(temp3, temp1, temp2), 7695); bigsetbig(temp4, temp1); bigsetbig(temp5, temp2); bigadd(temp1, bigmulint(temp1, temp1, 81), bigmulint(temp5, temp5, 1805)); bigadd(temp2, bigmulint(temp2, temp2, 5890), bigmulint(temp4, temp4, 7614)); if(croaks[i] == 'P') bigmulint(temp1, temp1, 2); else bigmulint(temp2, temp2, 2); bigmul(numerator, numerator, bigadd(temp4, temp1, temp2)); bigmul(denominator, denominator, bigmulint(temp3,temp3,3)); char string1[1000]; char string2[1000]; biggetstr(string1, numerator); biggetstr(string2, denominator); printf("%s/%s\n", string1, string2); } char string1[1000]; char string2[1000]; biggetstr(string1, numerator); biggetstr(string2, denominator); printf("%s/%s\n", string1, string2); return 0; }