Problem
You are given an array consisting of positive integers and a positive integer .
Find whether there exists a subset of the elements of such that the product of all elements of is divisible by .
Note that a subset is obtained by deleting some or no elements without changing the order of the remaining elements.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains two space-separated integers and — the number of elements of and the above mentioned integer .
- The second line of each test case contains space-separated integers representing the array .
Output Format
For each test case, print on a new line the answer: YES if there exists a subset and NO otherwise.
Each character of the output may be printed in either uppercase or lowercase, i.e, the strings Yes, YES, yes, yEs` will all be treated as identical.
solution of this queston --- Make sure to change the variable
#include<bits/stdc++.h>
using namespace std;
void solve()
{
long long a,b;
cin>>a>>b;
long long c =1;
long long ar[a];
bool flag = false;
for(int i=0; i<a; ++i)
{
cin>>ar[i];
}
for(int i=0; i<a; ++i)
{
c = (c*ar[i])%b;
}
if(c==0)
{
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
}
int main()
{
int t;
cin >>t;
while(t--)
{
solve();
}
}


No comments:
Post a Comment