-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp35.java
37 lines (31 loc) · 970 Bytes
/
p35.java
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
36
37
public class p35{
public static void main(String[] args){
int count =0;
outer:
for (int i = 2; i <= 1000000; i++){
for (int num : circle(i)){
if(!isPrime(num)){continue outer;}
}
count++;
}
System.out.println(count);
}
private static boolean isPrime(int n){
for (int i = 2; i <= Math.sqrt(n); i++){
if (n % i == 0){return false;}
}
return true;
}
private static int[] circle(int n){
StringBuilder nAsString = new StringBuilder(Integer.valueOf(n).toString());
int size = nAsString.length();
int[] circles = new int[size];
for (int i = 0; i < size; i++){
char digit = nAsString.charAt(0);
nAsString.delete(0,1);
nAsString.append(digit);
circles[i] = Integer.valueOf(nAsString.toString());
}
return circles;
}
}