Fixed problem with the algorithm.
If it's equal to half then we want to check if it's divisible, since if it's half then it is NOT prime.
This commit is contained in:
parent
a9019291c2
commit
06d5ddb0cc
@ -44,7 +44,7 @@ int main(void) {
|
|||||||
mpz_fdiv_q_ui(halfNum, num, 2);
|
mpz_fdiv_q_ui(halfNum, num, 2);
|
||||||
// Loop through found primes
|
// Loop through found primes
|
||||||
for(ulli i = 0; i < primes.end; ++i) {
|
for(ulli i = 0; i < primes.end; ++i) {
|
||||||
if(mpz_cmp(primes.list[i], halfNum) >= 0) break;
|
if(mpz_cmp(primes.list[i], halfNum) > 0) break;
|
||||||
// If `num' is divisible by a prime then go to the next number
|
// If `num' is divisible by a prime then go to the next number
|
||||||
if(mpz_divisible_p(num, primes.list[i]) != 0)
|
if(mpz_divisible_p(num, primes.list[i]) != 0)
|
||||||
goto nextPrime;
|
goto nextPrime;
|
||||||
|
Loading…
Reference in New Issue
Block a user