From 056a88ee9c2c9e26f9712d14c645e367d851f394 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 6 Aug 2019 16:56:43 +0200 Subject: c05 - primality test correction for ft_is_prime and ft_find_next_prime - queens puzzle solved with backtracking (similar to rush01) --- c05/ex06/ft_is_prime.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'c05/ex06') diff --git a/c05/ex06/ft_is_prime.c b/c05/ex06/ft_is_prime.c index 3c83061..658fefb 100644 --- a/c05/ex06/ft_is_prime.c +++ b/c05/ex06/ft_is_prime.c @@ -13,7 +13,6 @@ int ft_is_prime(int nb) { long unsigned int i; - long unsigned int nbu; if (nb <= 1) return (0); @@ -21,15 +20,12 @@ int ft_is_prime(int nb) return (1); if (nb % 2 == 0 || nb % 3 == 0) return (0); - i = 1; - nbu = nb; - while (i * i <= nbu) // ne fonctionne pas de 7 a 41 + i = 5; + while (i * i <= nb) { - if (nbu % (i * 6 - 1) == 0) - return (0); - if (nbu % (i * 6 + 1) == 0) - return (0); - i += 1; + if (nb % i == 0 || nb % (i + 2) == 0) + return (0); + i += 6; } return (1); } -- cgit