-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNGTO4.cpp
More file actions
49 lines (41 loc) · 719 Bytes
/
NGTO4.cpp
File metadata and controls
49 lines (41 loc) · 719 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <bits/stdc++.h>
#define maxx 1000006
using namespace std;
int T;
int f[maxx];
int a[] = {2,3,5,7};
void init()
{
f[2] = f[3] = f[5] = f[7] = 1;
for (int i = 0; i < 4; i++)
for (int j = 4; j < maxx; j++)
if (f[j-a[i]] != 0)
{
if (f[j] == 0) f[j] = f[j-a[i]]+1;
else f[j] = min(f[j], f[j-a[i]]+1);
}
}
void xuli()
{
}
void nhap()
{
cin >> T;
while(T--)
{
int x;
cin >> x;
if (f[x] == 0)
{
cout << -1 << "\n";
continue;
}
cout << f[x] << "\n";
}
}
int main(int argc, char const *argv[])
{
init();
nhap();
return 0;
}