コード例 #1
0
ファイル: primes_isprime.c プロジェクト: bszcz/c
int main(int argc, char** argv) {
	int maxnum = strtol(argv[1], NULL, 10);

	time_t t = clock();

	struct node* primes = addprime(2);
	struct node* current = primes;
	current->next = addprime(3);
	current = current->next;
	current->next = addprime(5);
	current = current->next;
	current->next = addprime(7);
	current = current->next;

	for (int num = 11; num <= maxnum; num += 2) {
		if (isprime(num)) {
			current->next = addprime(num);
			current = current->next;
		}
	}

	t = clock() - t;

	output(primes, maxnum, t, argc);
	destroy(primes);
	exit(EXIT_SUCCESS);
}
コード例 #2
0
ファイル: primes_boolean.c プロジェクト: bszcz/c
int main(int argc, char** argv) {
	const int maxnum = strtol(argv[1], NULL, 10);

	time_t t = clock();

	const int len = (maxnum - 1) / 2;
	char* isprime = malloc(len * sizeof(char));
	if (isprime == NULL) {
		printf("isprime == NULL\n");
		exit(EXIT_FAILURE);
	}
	memset(isprime, 1, len);

	int num = 3;
	while (num <= maxnum) {
		int rem = 3 * num;
		while (rem <= maxnum) {
			isprime[index(rem)] = 0;
			rem += 2 * num;
		}
		num += 2;
		while (num <= maxnum && ! isprime[index(num)]) {
			num += 2;
		}
	}

	struct node* primes = addprime(2);
	struct node* current = primes;
	num = 3;
	while (num <= maxnum) {
		if (isprime[index(num)]) {
			current->next = addprime(num);
			current = current->next;
		}
		num += 2;
	}

	t = clock() - t;

	output(primes, maxnum, t, argc);
	destroy(primes);
	free(isprime);
	exit(EXIT_SUCCESS);
}
コード例 #3
0
int main(){

	int i,j,k,l,test,t=1,num;

	buildprime(42768-100);
	takeprime(N-100);
	addprime();
	scanf("%d",&test);
	while(test--){
	    scanf("%d",&num);
		printf("%d\n",goldbach[num]);
	}

	return 0;
}