No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / groff / src / libs / libgroff / prime.cpp
blob8438995a4c8b3b872af56af8f5ba974112130c7d
1 /* $NetBSD$ */
3 #include <math.h>
5 int is_prime(unsigned n)
7 if (n <= 3)
8 return 1;
9 if (!(n & 1))
10 return 0;
11 if (n % 3 == 0)
12 return 0;
13 unsigned lim = unsigned(sqrt((double)n));
14 unsigned d = 5;
15 for (;;) {
16 if (d > lim)
17 break;
18 if (n % d == 0)
19 return 0;
20 d += 2;
21 if (d > lim)
22 break;
23 if (n % d == 0)
24 return 0;
25 d += 4;
27 return 1;