-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_12977.java
More file actions
31 lines (28 loc) · 841 Bytes
/
_12977.java
File metadata and controls
31 lines (28 loc) · 841 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
class Solution {
public int solution(int[] nums) {
initIsNotDecimal();
int answer = 0;
for(int a=0; a<nums.length-2; a++){
for(int b=a+1; b<nums.length-1; b++){
for(int c=b+1; c<nums.length; c++){
if(isDecimal(nums[a]+nums[b]+nums[c])) answer++;
}
}
}
return answer;
}
boolean[] isNotDecimal = new boolean[3001];
public void initIsNotDecimal(){
isNotDecimal[0] = isNotDecimal[1] = true;
for(int i=2; i<=3000; i++){
if(!isNotDecimal[i]){
for(int k=i*2; k<=3000; k+=i){
isNotDecimal[k] = true;
}
}
}
}
public boolean isDecimal(int i){
return !isNotDecimal[i];
}
}