Exemple #1
0
int main()
{
    int n = 10001;

    printf("The 10001st prime number is: %u\n", sieve_of_eratosthenes(n));

    return 0;
}
int main() {
	int n = 100, i;
	int *primes = NULL;
	// Find primes up to n
	int size = sieve_of_eratosthenes(&primes, n);
	printf("Primes up to %d are:\n", n);
	for(i = 0; i < size; ++i)
	{
		printf("%d\n", primes[i]);
	}
	return 0;
}
Exemple #3
0
/* 
 * ===  FUNCTION  ======================================================================
 *         Name:  main
 *  Description:  
 * =====================================================================================
 */
int main 
    ( 
    int argc, 
    char *argv[] 
    )
{
list * primes = sieve_of_eratosthenes(LIMIT);
node * cur_val = get_head(primes);
uint64_t sum_val = 0;

while(cur_val != NULL)
    {
    sum_val += *(uint64_t *)cur_val->data;
    cur_val = cur_val->next;
    }
printf("The sum of the primes under %d are: %lu\n", LIMIT, sum_val);
return EXIT_SUCCESS;
}				/* ----------  end of function main  ---------- */
Exemple #4
0
int main() {
  int res[1000001], num_res;
  num_res = sieve_of_eratosthenes(res, 1000000);

  int T;
  scanf("%d", &T);
  while(T--) {
    int N;
    scanf("%d", &N);
    int phi = N, i;
    for(i = 0; i < num_res && res[i]*res[i] <= N; ++i ) {
      if(N % res[i] == 0) {
        phi = (phi * (res[i] - 1))/res[i];
      }
      while(N % res[i] == 0) { 
        N = N/res[i];
      }
    }
    if (N > 1) phi -= phi / N; 
    printf("%d\n", phi);
  }
}