-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
40 lines (33 loc) · 1.08 KB
/
Main.java
File metadata and controls
40 lines (33 loc) · 1.08 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
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int testCase = sc.nextInt();
int[] arr = new int[50]; // 44개만 있어도 됩니다.
int sum = 2;
arr[0] = 1;
for(int i=1; i<arr.length; i++){
arr[i] = arr[i-1] + sum;
sum++;
}
boolean[] isTriangleNum = new boolean[1001]; // 3~1000까지 3개의 합으로 표현 가능한 수
for(int i=0; i<arr.length; i++){
for(int j=0; j<arr.length; j++){
for(int k=0; k<arr.length; k++){
int idx = arr[i] + arr[j] + arr[k];
if(idx > 1000) continue;
else isTriangleNum[idx] = true;
}
}
}
for(int i=0; i<testCase; i++){
int num = sc.nextInt();
if(isTriangleNum[num]) {
System.out.println(1);
} else {
System.out.println(0);
}
}
sc.close();
}
}