#include<iostream>
#include<cstdio>
#define MAX 10001
#define MAX2 100
using namespace std;
int N,K;
int A[MAX];
bool result[MAX][MAX2],count[MAX][MAX2];
void init()
{
int i,j;
for(i=0;i<MAX;i++)
for(j=0;j<MAX2;j++)
count[i][j]=false;
return ;
}
bool div(int n,int k)
{ //printf("Calling(%d %d)\n",n,k);
if(count[n][k]==true)return result[n][k];
int k1=A[n]%K;
if(k1<0)k1=K+k1;
if(n==1 ){ if( (k1==k) || ( (K-k1)%K ==k) )return true;
else return false;
}
bool c,d;
c=div(n-1,(k+k1)%K );
count[n-1][(k+k1)%K]=true;
result[n-1][(k+k1)%K]=c;
//printf("calling 1 ( %d %d),result %d\n",n-1,(A[n] %K),c);
d=div(n-1,(k-k1)%K);
count[n-1][(k-k1)%K]=true;
result[n-1][(k-k1)%K]=d;
//printf("calling 2( %d %d),result %d \n",n-1,(A[n] %K),d);
if( c==true || d==true) return true;
else return false;
}
int main()
{
int tc;
cin>>tc;
while(tc--){ init();
cin>>N>>K;
for(int i=1;i<=N;i++)cin>>A[i];
//for(int i=1;i<=N;i++)cout<<A[i];
if(div(N,0))cout<<"Divisible"<<endl;
else cout<<"Not divisible"<<endl;
}
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন