44 lines
1.2 KiB
C
44 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_find_next_prime.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/07/23 23:24:05 by adjoly #+# #+# */
|
|
/* Updated: 2023/07/31 09:59:29 by adjoly ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
int ft_is_prime(int nb)
|
|
{
|
|
int i;
|
|
|
|
i = 2;
|
|
if (nb == 2147483647)
|
|
return (1);
|
|
if (nb <= 0 || nb == 1)
|
|
return (0);
|
|
if (nb % 2 == 0)
|
|
return (0);
|
|
while (i < nb / 2)
|
|
{
|
|
if (nb % i == 0)
|
|
return (0);
|
|
i++;
|
|
}
|
|
return (1);
|
|
}
|
|
|
|
int ft_find_next_prime(int nb)
|
|
{
|
|
int i;
|
|
|
|
i = nb;
|
|
if (nb <= 2)
|
|
return (2);
|
|
while (ft_is_prime(i) != 1)
|
|
i++;
|
|
return (i);
|
|
}
|