-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAMITNINI.cpp
More file actions
73 lines (60 loc) · 1 KB
/
AMITNINI.cpp
File metadata and controls
73 lines (60 loc) · 1 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;
typedef long long LL;
LL s[35];
LL INF = 10L * 1000L * 1000L * 1000L;
set<LL> sumOdd, sumEven;
void calckSums(int start, int n, set<LL> &sums)
{
sums.clear();
sums.insert(0);
int k = (n - start + 2) / 2;
for (int mask = (1<<k)-1; mask > 0; mask--)
{
LL sum = 0;
for (int j = 0; j < k; j++)
if ((int)(mask&(1<<j)) != 0)
sum += s[start + 2*j];
sums.insert(sum);
}
}
void calckSums(int n)
{
calckSums(1, n, sumOdd);
calckSums(2, n, sumEven);
}
void gen()
{
s[1] = 2;
s[2] = 7;
int n = 3;
for (; s[n-1] <= INF; n++)
if (n%2 == 1) s[n] = s[n-1] + 3 * s[n-2];
else s[n] = s[n-1] + 7;
calckSums(n-2);
}
void solve()
{
LL n;
cin >> n;
for (LL s1 : sumOdd)
if (sumEven.count(n-s1) > 0)
{
cout << "YES" << endl;
return;
}
cout << "NO" << endl;
}
int main() {
gen();
int t;
cin >> t;
for (int tc = 0; tc < t; tc++)
solve();
return 0;
}