repo.or.cz
/
netbsd-mini2440.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
No empty .Rs/.Re
[netbsd-mini2440.git]
/
gnu
/
dist
/
groff
/
src
/
libs
/
libgroff
/
prime.cpp
blob
8438995a4c8b3b872af56af8f5ba974112130c7d
1
/* $NetBSD$ */
2
3
#include <math.h>
4
5
int
is_prime
(
unsigned
n
)
6
{
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
;
26
}
27
return
1
;
28
}