-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq35.java
More file actions
35 lines (28 loc) · 698 Bytes
/
q35.java
File metadata and controls
35 lines (28 loc) · 698 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import helpers.helpers;
import java.math.*;
public class q35 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int count = 0;
for(int i = 3; i < 1000001; ++i){
String s = String.valueOf(i);
String c = "2";
if(s.contains(c) || !helpers.isPrime(i)) continue;
if(checkCircular(i)){
++count;
System.out.println("Circular Prime: " + i);
}
}
System.out.println(count);
}
public static boolean checkCircular(int i){
int length = helpers.numDigits(i);
for(int j = 1; j < length; ++j){
int rem = i % 10;
i /= 10;
i += Math.pow(10, length-1) * rem;
if(!helpers.isPrime(i)) return false;
}
return true;
}
}