-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10448.c
50 lines (40 loc) · 918 Bytes
/
10448.c
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
// https://www.acmicpc.net/problem/10448
// 유레카 이론
#include <stdio.h>
#define MAX_SIZE 1000
#define Nth 45 // 45th triangular number is 2070. 1st ~ 44th triangular numbers will be used.
int is_eureka(int K);
int main(void)
{
int T;
int K[MAX_SIZE];
scanf("%d", &T);
for(int i=0; i<T; i++)
scanf("%d", &K[i]);
for(int i=0; i<T; i++)
printf("%d\n", is_eureka(K[i]));
return 0;
}
int is_eureka(int K)
{
int tri[Nth] = {0};
int ith = 45, T_i;
for(int i=1; i<Nth; i++) {
T_i = (i * (i + 1)) / 2;
if(T_i < K)
tri[i] = T_i;
else {
ith = i;
break;
}
}
for(int i=1; i<ith; i++) {
for(int j=i; j<ith; j++) {
for(int k=j; k<ith; k++) {
if(tri[i] + tri[j] + tri[k] == K)
return 1;
}
}
}
return 0;
}