Esempio n. 1
0
int main(const int argc, const char *argv[]){
    num_t sieve_limit = LIMIT;
    char *primes = malloc(sieve_limit+1);

    eratosthenes(primes, sieve_limit);
    printf("%lld\n", get_nth_prime(NTH, primes, sieve_limit));
    
    free(primes);
    return 0;
}
Esempio n. 2
0
int main() {
  int t;
  eratosthenes(1000000);
  scanf("%d", &t);
  while (t--) {
    long long n;
    scanf("%I64d", &n);
    long long i = (long long) sqrt(n);
    if (i * i == n && !prime[i]) printf("YES\n");
    else printf("NO\n");
  }
  return 0;
}
Esempio n. 3
0
int main(int argc, char** argv)
{
	int x[DIM]; /* Vector x element R^n */
	
	initialize(x, DIM);
	
	eratosthenes(x, DIM);

	printf("Sorted vector x[%d]:\n", DIM);
	printvector(x, DIM);

	return EXIT_SUCCESS;
}
void createIrredPolys (Poly* irredPolys)
{
    // Use the following map for Eratosthenes' sieve

    int mapSize = 100;
    bool* map = 0;

    int count;

    do
    {
        mapSize *= 2;

        // dump old table and create a new one

        delete[] map;
        map = new bool [mapSize];

        // find irreducible polynomials

        eratosthenes (map, mapSize, Poly (0));

        // Count irreducible polynomials in this map

        count = 0;

        for (int i = 0; i < mapSize; i++) if (map [i]) count++;

    } while (count < NiederreiterMatrix::MAX_DIM);  // do we have enough?

    // Copy the first MAX_DIM irreducible polynomials to irredPolys

    bool* p = map;

    for (int i = 0; i < NiederreiterMatrix::MAX_DIM; i++)
    {
        while (! *p) p++;

        irredPolys [i] = Poly (p++ - map);
    }

    // Free the memory used for the map

    delete[] map;
}
Esempio n. 5
0
int main(const int argc, const char *argv[]){
    num_t a, b, nconsec,
        max_a=-COEF_LIMIT, max_b=-COEF_LIMIT, max_consec=0;
    char *primes = eratosthenes(PRIME_LIMIT);

    for (a=-COEF_LIMIT; a<COEF_LIMIT; a++)
        for (b=-COEF_LIMIT; b<COEF_LIMIT; b++){
            nconsec = count_consecutive(primes, a, b);
            if (nconsec > max_consec) {
                max_consec = nconsec;
                max_a = a;
                max_b = b;
            }
        }

    printf("%lld\n", max_a*max_b);
    
    free(primes);
    return 0;
}
Esempio n. 6
0
int main(int argc, char **argv)
{
  if(argc == 2) eratosthenes(atoi(argv[1]));
  else eratosthenes(50);
  return 0;
}