* Makefile.in (ENVSETUP): Don't assume POSIX make semantics for
[s-roff.git] / src / libs / libgroff / prime.cc
blobf0b1eadcc68be71801a927f6d92cfddbf2697a0d
1 #include <math.h>
3 int is_prime(unsigned n)
5 if (n <= 3)
6 return 1;
7 if (!(n & 1))
8 return 0;
9 if (n % 3 == 0)
10 return 0;
11 unsigned lim = unsigned(sqrt((double)n));
12 unsigned d = 5;
13 for (;;) {
14 if (d > lim)
15 break;
16 if (n % d == 0)
17 return 0;
18 d += 2;
19 if (d > lim)
20 break;
21 if (n % d == 0)
22 return 0;
23 d += 4;
25 return 1;