-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReID.java
More file actions
56 lines (45 loc) · 1.13 KB
/
ReID.java
File metadata and controls
56 lines (45 loc) · 1.13 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.ArrayList;
class Solution {
private static final int MAX_SL = 10005;
private static ArrayList<Long> primes = new ArrayList<>();
private static StringBuilder sb = new StringBuilder();
static {
computePrimes();
}
private static void computePrimes() {
primes.add(2l);
sb.append(2);
long i = 3;
while(sb.length() < MAX_SL) {
if(isPrime(i)) {
primes.add(i);
sb.append(i);
}
i += 2;
}
}
private static boolean isPrime(long num) {
for(long i: primes) {
if(num % i == 0) {
return false;
}
if(i*i > num) {
return true;
}
}
return true;
}
public static String solution(int i) {
// Your code here
return sb.substring(i, i+5);
}
}
public class ReID {
public static void main(String args[]) {
System.out.println(Solution.solution(0));
System.out.println(Solution.solution(1));
System.out.println(Solution.solution(2));
System.out.println(Solution.solution(3));
System.out.println(Solution.solution(10000));
}
}