int main() { PrimeSieve primes(MAX); unsigned max = 1, maxprime; unsigned sum; for(size_t length = 6; length < primes.size(); ++length) { for(size_t i = 0; i + length <= primes.size(); ++i) { sum = 0; for(size_t j = 0; j < length; ++j) { sum += primes[i + j]; if(sum >= MAX) break; } if(sum >= MAX) break; if(primes.isPrime(sum)) { max = length; maxprime = sum; } } } std::cout << maxprime << ' ' << max << std::endl; return 0; }
int main(int argc,char **argv) { if(argc != 2) { fprintf(stderr,"%s [prime|pqg]\n",argv[0]); exit(1); } if(!FIPS_mode_set(1,argv[0])) { ERR_load_crypto_strings(); ERR_print_errors(BIO_new_fp(stderr,BIO_NOCLOSE)); exit(1); } if(!strcmp(argv[1],"prime")) primes(); else if(!strcmp(argv[1],"pqg")) pqg(); else if(!strcmp(argv[1],"keypair")) keypair(); else if(!strcmp(argv[1],"siggen")) siggen(); else if(!strcmp(argv[1],"sigver")) sigver(); else { fprintf(stderr,"Don't know how to %s.\n",argv[1]); exit(1); } return 0; }
int64_t Problem35::solve() { Primes primes(1000000); std::set<int64_t> circularPrimes; for(const auto &i : primes.getPrimes()) { auto rotations = getRotations(i); bool circular = true; for(auto &j : rotations) { if(j < i || !primes.isPrime(j)) { circular = false; break; } } if(circular) { for(auto &j : rotations) circularPrimes.insert(j); } } return circularPrimes.size(); }
static PyObject* primes(PyObject* self, PyObject* args){ Py_ssize_t start = 0, n = 0; size_t pi; if (!PyArg_ParseTuple(args, "n|n:primes", &start, &n)) return NULL; if (PyTuple_Size(args) == 1){ n = start; start = 0; } if (start > n) return PyList_New(0); if (start < 2) start = 2; if (n < 3) return PyErr_Occurred() ? NULL : PyList_New(0); else if (n == 3){ PyObject* just_two = PyList_New(1); PyList_SET_ITEM(just_two, 0, PyInt_FromLong(2)); return just_two; } else if (n < 6) pi = 2; else if (n < 8) pi = 3; else if (n < 12) pi = 4; else if (n < 14) pi = 5; else if (n < 18) pi = 6; else pi = n/(log(n)-1); size_t i = 0; PrimePyList primes(pi, &i); PrimeSieve ps; ps.generatePrimes(start, n-1, &primes); i--; while (i < --pi) PyObject_CallMethod(primes.list, (char*)"__delitem__", (char*)"(n)", pi); return primes.list; }
std::vector<ullong> generatePrimes() { ullong upperBound = std::ceil(std::sqrt(N)); bool sieve[N] = {0}; std::vector<ullong> primes(N/2 + 1); ullong insert = 3; primes[0] = 2; primes[1] = 3; primes[2] = 5; for(ullong i = 1; i <= upperBound; ++i) { for(ullong j = 1; j <= upperBound; ++j) { ullong n = (4*i*i)+(j*j); if(n <= upperBound && (n % 12 == 1 || n % 12 == 5)) sieve[n] = !sieve[n]; n = (3*i*i)+(j*j); if(n <= upperBound && (n % 12 == 7)) sieve[n] = !sieve[n]; n = (3*i*i)-(j*j); if((i > j) && (n <= upperBound) && (n % 12 == 11)) sieve[n] = !sieve[n]; } } for(ullong i = 5; i <= upperBound; ++i) { if(sieve[i]) { for(ullong j = i*i; j < upperBound; j += i*i) sieve[j] = false; } } for(ullong i = 7; i < upperBound; i += 2) { if(sieve[i]) { primes[insert] = i; ++insert; } } return primes; }
/* O main usa a mesma logica do nosso EP. Ele pega os numeros que estao num arquivo A, recolhe somente os que estao dentro do intervalo [p,r] e depois filtra os primos dos numeros recolhidos usando a funcao primes. */ int main( int argc, char **argv ) { if ( argc != 5 ) { printf("Uso <num> <num> <falenamein> <falinameout> \n"); } else { unsigned int p, r, i, number, *primen; FILE *pfilein, *pfileout; p = atoi(argv[1]); r = atoi(argv[2]); pfilein = fopen( argv[3], "r"); pfileout = fopen( argv[4], "w"); primen = malloc(MAX_SIZE*sizeof(int)); if ( pfilein == NULL ) printf("Seu feio. \n"); fscanf(pfilein,"%u", &number); for ( i = 0 ; fscanf(pfilein,"%u", &number) != EOF; ) { if( number >= p && number <= r ) { primen[i] = number; i++; } fscanf(pfilein,"%u", &number); } primes( primen, i, pfileout ); } return 0; }
int main(){ output_primes(primes(2,100)); //vector<int> prime_numbers = primes(lower, max); //output_primes(prime_numbers, lower, max); }
int main(void) { primes(); //for(int i=0;i<count;i++) // printf("%d ",prime[i]); int t; scanf("%d",&t); while(t--) { int a,b,n; scanf("%d %d %d",&a,&b,&n); if(n==0) { printf("1\n"); continue; } int answer=0; for(int i=a;i<=b;i++) { if(i==1) { factorful[1]=0; continue; } if(factorful[i]==0) { int check=checkFactors(i); factorful[i]=check; } if(factorful[i]==n) answer++; } printf("%d\n",answer); } }
int main() { sieve_of_eratosthenes<long> primes(bound); long resilient = 1; long curr = 1; for (int i = 2; i < bound; ++i) { if (!primes[i]) { continue; } resilient *= i - 1; curr *= i; if (resilient * bound_d < bound_n * (curr - 1)) { int base = curr / i; int rbase = resilient / (i - 1); for (int j = 2; j < i; ++j) { if (j * rbase * bound_d < bound_n * (base * j - 1)) { std::cout << base * j << std::endl; return 0; } } std::cout << curr << std::endl; return 0; } } return 0; }
int main(int argc, char** argv) { if(argc == 1) { mqd_t queue_in, queue_out; makeQueues(&queue_in, &queue_out); if(MQ_ERROR == queue_in || MQ_ERROR == queue_out) { perror("Nie udało się utworzyć kolejki"); exit(0); } else { msg_t order; unsigned priority = 0; mq_receive(queue_in, (char*)&order, sizeof(msg_t), &priority); order.count = primes(order.begin, order.end); printf("Numer procesu: %d, liczby pierwsze: %d\n", getpid(), order.count); mq_send(queue_out, (char*)&order, sizeof(msg_t), 10); } } return 0; }
int main() { int in; std::scanf("%d", &in); primes( in/2 ); std::vector< std::pair<int , int > > out; for( int i(0) ; i < int(data.size() ) ; ++i ) if(data[i]%in == 0 ) out.push_back( std::make_pair( data[i] , in/data[i] ) ); if( out.empty() ) std::printf("0\n"); else { for( int i(0) ; i < int( out.size() ) ; ++i ) std::printf("%d\n",out[i].first); for( int i( int(out.size()) -1) ; i >= 0 ; --i ) std::printf("%d\n",out[i].second); } return 0; }
int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "%s [prime|pqg|pqgver|keypair|siggen|sigver]\n", argv[0]); exit(1); } if (!FIPS_mode_set(1)) { do_print_errors(); exit(1); } if (!strcmp(argv[1], "prime")) primes(); else if (!strcmp(argv[1], "pqg")) pqg(); else if (!strcmp(argv[1], "pqgver")) pqgver(); else if (!strcmp(argv[1], "keypair")) keypair(); else if (!strcmp(argv[1], "keyver")) keyver(); else if (!strcmp(argv[1], "siggen")) siggen(); else if (!strcmp(argv[1], "sigver")) sigver(); else { fprintf(stderr, "Don't know how to %s.\n", argv[1]); exit(1); } return 0; }
int main(void) { // first compute all 10-digit primes long *p, np; primes(PMAX, &p, &np); int max_counts[10]; memset(max_counts, 0, sizeof(max_counts)); uint64_t max_sums[10]; memset(max_sums, 0, sizeof(max_sums)); int counts[10]; long i; for(i = 0; i < np; i++) { if(p[i] < PMIN) continue; if(p[i] > PMAX) break; get_counts(p[i], counts); update_maxes(p[i], counts, max_counts, max_sums); } uint64_t result = 0; for(i = 0; i < 10; i++) result += max_sums[i]; printf("result: %ld\n", result); return 0; }
int main(void) { int n; primes(); scanf("%d",&n); printf("%d\n",primeArray[n]); }
/* * Test 1 * */ void provaCalcS(){ printf("halloo, probando probando!!\n"); vector pc = zerov(2); vector pcPrimes = zerov(2); matrix S = zerom(2, 3); pc.v[0] = 50; pc.v[1] = 200; //Test in matlab //S = [ 0 0.0003495 0.002; 0.0018 0.0338 0.0207]; S.m[0][0] = 0; S.m[0][1] = 0.0003495; S.m[0][2] = 0.002; S.m[1][0] = 0.0018; S.m[1][1] = 0.0338; S.m[1][2] = 0.0207; int numPrimes = (int)(pc.v[pc.x - 1] / pc.v[0]); intvector numsPrimesReason = primes(numPrimes); int i, j; for(i = 0; i < numsPrimesReason.x; ++i){ printf("i: %d\n", numsPrimesReason.v[i]); int primeNum = numsPrimesReason.v[i]; for(j = 0; j < pcPrimes.x; ++j){ pcPrimes.v[j] = pc.v[j] * primeNum; } printf("\nArray pcPrimes:\n"); printv(pcPrimes); matrix SnInterp = interp1Mat(pc, pcPrimes, S, 0); printf("\nResult S\n"); printm(SnInterp); } }
static void Make_SeedTable(Fasta *fst, int **table_value, unsigned short **table_num){ int i,j; int hashsize = primes((int)(par.blocksize*1.2)); int start, end, num, seedvalue, M_b=idata_b->blocknum[idata_b->cnt]; struct seed *hash = (struct seed *)my_malloc(hashsize * sizeof(struct seed), "hash"); struct seed *seedlist_temp = (struct seed *)my_malloc(par.blocksize * sizeof(struct seed), "seedlist_temp"); for(i=0; i<M_b; i++){ for(j=0; j<hashsize; j++) hash[j].value = -1; start = i*par.blocksize; if(i==M_b-1) end = fst->length - window[par.kmer_ba]; else end = (i+1)*par.blocksize; for(j=start; j<end; j++){ seedvalue = SeedScoring_masked(fst, j, par.kmer_ba); if(seedvalue != -1) hashing(seedvalue, hash, hashsize); } num=0; for(j=0; j<hashsize; j++){ if(hash[j].value != -1) seedlist_temp[num++] = hash[j]; } table_value[i] = (int *)my_malloc((num+1) * sizeof(int), "table_b_value[i]"); table_num[i] = (unsigned short *)my_malloc((num+1) * sizeof(unsigned short), "table_b_num[i]"); for(j=0; j<num; j++){ table_value[i][j] = seedlist_temp[j].value; table_num[i][j] = seedlist_temp[j].num; } table_value[i][num] = -1; /* guard */ } free(seedlist_temp); free(hash); return; }
int main(int argc, char **argv) #endif { FILE *in, *out; if (argc == 4) { in = fopen(argv[2], "r"); if (!in) { fprintf(stderr, "Error opening input file\n"); exit(1); } out = fopen(argv[3], "w"); if (!out) { fprintf(stderr, "Error opening output file\n"); exit(1); } } else if (argc == 2) { in = stdin; out = stdout; } else { fprintf(stderr,"%s [prime|pqg|pqgver|keypair|keyver|siggen|sigver]\n",argv[0]); exit(1); } fips_algtest_init(); if(!strcmp(argv[1],"prime")) primes(in, out); else if(!strcmp(argv[1],"pqg")) pqg(in, out); else if(!strcmp(argv[1],"pqgver")) pqgver(in, out); else if(!strcmp(argv[1],"keypair")) keypair(in, out); else if(!strcmp(argv[1],"keyver")) keyver(in, out); else if(!strcmp(argv[1],"siggen")) siggen(in, out); else if(!strcmp(argv[1],"sigver")) sigver(in, out); else { fprintf(stderr,"Don't know how to %s.\n",argv[1]); exit(1); } if (argc == 4) { fclose(in); fclose(out); } return 0; }
int main() { int input, output; printf("Input N: "); scanf("%d",&input); output = primes(input); printf("output: %d\n",output); return 0; }
int main() { int a[10] = {0,0,0,0,0,0,0,0,0,0}; primes(a); int i; for (i=0;i<10;++i){ printf("%d ",a[i]); } printf("\n"); }
void mySortFunc(float *array) { std::vector <float> primes(array, array + BLOCKSIZE); std::sort( primes.begin(), primes.end(), myCompareFunc); for(int i=0; i < BLOCKSIZE; i++) { array[i] = primes.at(i); } }
int main() { long long int max = 0; long long int * ps = primes(600851475143); for (long long int * p = ps; *p != 0; p++) { if (*p > max) { max = *p; } } printint(max); free(ps); }
int main(int argc, const char *argv[]) { int start = 0; int end = 0; scanf("%d", &start); scanf("%d", &end); primes(start, end); return 0; }
int main(int argc, char** argv) { if(argc == 2) { int begin, end, process_number; struct results res = {0}; sscanf(argv[1], "%d", &process_number); //printf("Proces %d: Otwieranie pipe IN\n", process_number); int fifo_in = open(FIFO_IN_NAME, O_RDONLY); //printf("Proces %d: Ukończono otwieranie pipe IN\n", process_number); //printf("Proces %d: Otwieranie pipe OUT\n", process_number); int fifo_out = open(FIFO_OUT_NAME, O_WRONLY); //printf("Proces %d: Ukończono otwieranie pipe OUT\n", process_number); // Jeśli otwarto pipe'y if(fifo_in > 0 && fifo_out > 0) { // printf("Proces %d: Rozpoczęcie czytania\n", process_number); while(read(fifo_in, &res, sizeof(res)) > 0) { begin = res.begin; end = res.end; if(res.begin == -1) break; int primes_number = primes(begin, end); // printf("Numer procesu: %d, liczby pierwsze: %d\n", // process_number, // primes_number); res.begin = begin; res.end = end; res.count = primes_number; // printf("Proces %d: Rozpoczęcie pisania\n", process_number); int written = write(fifo_out, &res, sizeof(res)); // printf("Proces %d: Koniec pisania\n", process_number); } // printf("Proces %d: Koniec czytania\n", process_number); close(fifo_in); close(fifo_out); } else { perror("Nie udało się otworzyć pipe\n"); } printf("Proces %d: Koniec działania\n", process_number); } return 0; }
int main() { long *p; long np; primes(N, &p, &np); printf("np: %ld == Pi(%ld)\n", np, N); int pi = 0; int64_t i; uint64_t *scores = calloc(N+1, sizeof(uint64_t *)); scores[0] = 1; uint64_t S = 6ul; // C(1) == 6 printf("C(1) == 6, S(1) == 6\n"); for(i = 2; i <= N; i++) { int64_t j; // j is score uint64_t tmp0 = scores[0]; scores[0] *= 5ul; scores[0] %= MODULUS; for(j = 1; j <= MIN(i, np); j++) { uint64_t tmp1 = scores[j]; scores[j] *= 5ul; scores[j] += tmp0; scores[j] %= MODULUS; tmp0 = tmp1; } if(p[pi] == i) { pi++; } uint64_t C = 0; for(j = 0; j <= pi; j++) { C += 6ul*scores[j]; C %= MODULUS; } S += C; #ifdef VERBOSE printf("C(%ld) == %ld, S(%ld) == %ld\n", i, C, i, S); #endif S %= MODULUS; } printf("S(%ld) == %ld\n", N, S); return 0; }
void bit_sieve() { std::vector<bool> primes (MAX_VAL, true); std::vector<bool>::iterator it, lead_iter; int i; primes[0] = primes[1] = false; for (i = 0, it = primes.begin(); i <= MAX_VAL && it < primes.cend(); ++it, ++i) if (*it) for (lead_iter = it + i; lead_iter < primes.cend(); lead_iter += i) *lead_iter = false; }
void std::vector<int> prune(std::vector<bool> &flags, int count) { std::vector<int> primes(count); int index = 0; for (int i = 0; i < flags.size(); i++) { if (flags[i]) { primes[index] = i; index++; } } return primes; }
int64_t Problem71::solve() { Fraction limit(3, 7); Fraction max(0, 1); Primes primes(PROBLEM_SIZE); for(int i = 8; i <= PROBLEM_SIZE; ++i) { Fraction curr(limit * i, i); if(curr < max) continue; else if(curr.isProperFraction(primes)) max = curr; } return max.getNumerator(); }
int main() { int tot = primes(Max_M), n; for(scanf("%d", &_); _--; ) { scanf("%d", &n); init(n); for(int i = 0; i < n; ++i) { scanf("%d", bn + i); } for(int i = 0, j; i < n; ++i) { for(j = i+1; j < n; ++j) if(Check(bn[i], bn[j])) { add(i, j); } } static int cas = 0; printf("Case #%d: %d\n", ++cas, n - hungary(n)); } return 0; }
int main() { std::vector<bool> primes(bound, true); std::vector<size_t> primes_list; std::unordered_map<size_t, std::vector<size_t>> divisors; primes[0] = primes[1] = false; for (size_t curr = 2; curr < bound; ++curr) { if (!primes[curr]) { continue; } primes_list.push_back(curr); for (size_t visitor = curr * 2; visitor < bound; visitor += curr) { primes[visitor] = false; } } for (size_t curr = 2; curr < bound; ++curr) { if (!primes[curr]) { continue; } for (size_t visitor = curr * 2; visitor < bound; visitor += curr) { if (primes[visitor - 1]) { divisors[visitor - 1].push_back(curr); } } } for (size_t idx = 1; idx < primes_list.size() - 1; ++idx) { process(primes, primes_list[idx] + 1, 1, 0, divisors[primes_list[idx]]); } std::cout << result << std::endl; return 0; }
lint_iterator decompose (lint in_n){ YIELDS(lint); lint n = in_n; /* for p in primes do */ FOR(lint p, primes()){ if( p*p > n ){ BREAK; } else { while( n % p == 0 ){ YIELD(p); n = n / p; } } CONTINUE; } if( n > 1 ){ YIELD(n); } }