Toggle navigation
Home
Latest pastes
FAQ
Random
Register
Login
#Java - isPrime
SUBMITTED BY:
Guest
DATE:
May 21, 2014, 12:30 p.m.
FORMAT:
Java
SIZE:
614 Bytes
Raw
Download
Tweet
HITS:
1004
Go to comments
Report
public
static
boolean
isPrime
(
long
i
)
{
if
(
i
<
2
)
return
false
;
if
(
i
==
2
|
i
==
3
)
{
return
true
;
}
if
(
i
%
2
==
0
||
i
%
3
==
0
)
return
false
;
String
asS
=
String
.
valueOf
(
i
);
if
(
asS
.
endsWith
(
"5"
)
|
asS
.
endsWith
(
"0"
))
return
false
;
long
sqrtN
=
(
long
)
Math
.
sqrt
(
i
)
+
1
;
for
(
long
j
=
6L
;
j
<=
sqrtN
;
j
+=
2
)
{
if
(
i
%
(
j
-
1
)
==
0
||
i
%
(
j
+
1
)
==
0
)
return
false
;
}
return
true
;
}
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus