-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_isprime.c
33 lines (30 loc) · 1.17 KB
/
ft_isprime.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isprime.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sebasnadu <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/10 20:21:17 by sebasnadu #+# #+# */
/* Updated: 2024/02/11 11:54:39 by sebasnadu ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../include/libft.h"
bool ft_isprime(size_t n)
{
size_t i;
if (n <= 1)
return (false);
if (n <= 3)
return (true);
if ((n & 1) == 0 || n % 3 == 0)
return (false);
i = 5;
while ((i * i) <= n)
{
if ((n % i) == 0 || (n % (i + 2)) == 0)
return (false);
i += 6;
}
return (true);
}