repo.or.cz
/
s-roff.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
* Makefile.in (ENVSETUP): Don't assume POSIX make semantics for
[s-roff.git]
/
src
/
libs
/
libgroff
/
prime.cc
blob
f0b1eadcc68be71801a927f6d92cfddbf2697a0d
1
#include <math.h>
2
3
int
is_prime
(
unsigned
n
)
4
{
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
;
24
}
25
return
1
;
26
}