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
file_case.{h,cpp}: wether->whether; 2017
[s-roff.git]
/
src
/
lib-roff
/
prime.cpp
blob
7c80c34ada32874e10fa2676a190541953ab4ba1
1
/*@ */
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
}
29
30
// s-it2-mode