Esempio n. 1
0
int main() {
    uint64_t number=1;
    uint16_t counter=0;
    _Bool condition=TRUE;
    while(condition)
        if(checkIfPrime(++number) == TRUE)
            if(++counter == 10001)
                condition=FALSE;
    printf("found prime: %" PRIu64 "\n",number);
    return 0;
}
Esempio n. 2
0
int main(void){
	int N, a, prime=0;
	printf("Enter integer N: ");
	scanf("%i",&N);
	for(a=N;a>1;a--){
		if(checkIfPrime(a)) prime++;
	}
	printf("The total of prime numbers less than or equal to %i is %i.\n",N,prime);
	getch();
	return 0;
}
Esempio n. 3
0
int main() {
    // Get all the primes below the coefficient limit (1000)
    int numPrimes = 0, *primes;
    getPrimesBelowLimit(&primes, &numPrimes);

    int a, b, i, j, n;
    int maxN = 0, coeffA, coeffB;

    // For each possible 'a' value (from -999 to 999)
    for (a = -1*COEFFICIENT_LIMIT + 1; a < COEFFICIENT_LIMIT; a++) {

        // For each possible 'b' value (prime numbers between -1000 and 1000)
        // 'b' has to be a prime number 'p'; when n = 0, (0*0 + 0*a + b = p)
        for (i = 0; i < numPrimes; i++) {
            for (j = -1; j < 2; j += 2) {
                b = j * primes[i];
                
                // Start at n = 0, continue to evaluate formula for increasing n
                // until the returned result is not prime
                n = 0;
                while ( checkIfPrime(evaluateFormula(n, a, b)) != 0 )
                    n++;

                // Update the maximum number of consecutive primes
                if (n > maxN) {
                    maxN = n;
                    coeffA = a;
                    coeffB = b;
                }
            }
        }
    }

    printf("%d consecutive values of n (a=%d, b=%d)\n", maxN, coeffA, coeffB);
    printf("%d*%d = %d\n", coeffA, coeffB, coeffA*coeffB);
}