-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathuva-10036.cpp
49 lines (34 loc) · 820 Bytes
/
uva-10036.cpp
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
//uva 10036
//Divisibility
#include <iostream>
#include <vector>
using namespace std;
int main(void)
{
int T = 0;
cin >> T;
while (T--) {
int n = 0, k = 0;
cin >> n >> k;
vector <bool> rem(k);
int num;
cin >> num;
rem[abs(num % k)] = 1;
for (int i = 1; i < n; ++i){
cin >> num;
num = abs(num % k);
vector <bool> _rem_tmp(k, 0);
for (int i = 0; i < k; ++i)
if (rem[i]){
_rem_tmp[(i + num) % k] = 1;
_rem_tmp[abs((i - num) % k)] = 1;
}
rem = _rem_tmp;
}
if (rem[0])
cout << "Divisible" << endl;
else
cout << "Not divisible" << endl;
}
return 0;
}