File size: 1,166 Bytes
c4b0eef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#include<bits/stdc++.h>
#define Sakr_ ios_base :: sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0);
#define ll  long long
#define pi 3.14159265
using namespace std;
/*
by:Ahmed Sakr (sakr_) with AZA ;
#ifndef ONLINE_JUDGE
   freopen("c.in", "r", stdin);
#endif
  __builtin_popcount();
*/
bool isPrime(int x) {
    if (x <= 1) return false;
    if (x <= 3) return true;
    if (x % 2 == 0 || x % 3 == 0) return false;
    for (int i = 5; i * i <= x; i = i + 6)
        if (x % i == 0 || x % (i + 2) == 0) return false;
    return true;
}
int n,k;
vector<int> arr;
vector<vector<int>> dp;
bool solve(int i,int sum){
    if(i==n) {

        if(sum==0) return 1;

        return 0;
    }

    if(dp[i][sum] != -1) return dp[i][sum];

    return dp[i][sum] = ((solve(i+1,abs(sum+arr[i])%k)) || (solve(i+1,abs(sum-arr[i])%k)));



}

int32_t main() {
    Sakr_

    int t,i;
    cin>>t;

    while (t--) {
        cin>>n>>k;
        arr= vector<int>(n+2);
        dp = vector<vector<int>>(n+2,vector<int>(k+2,-1));

        for(i=0;i<n;i++) {
            cin>>arr[i];
        }
        cout<<(solve(1,arr[0]%k)?"Divisible\n":"Not divisible\n");

    }



    return 0;
}