Today Pari and Arya are playing a game called Remainders.
Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value . There are n ancient numbers c_1, _c_2, …, _c__n and Pari has to tell Arya if Arya wants. Given k and the ancient values, tell us if Arya has a winning strategy independent of value of x or not. Formally, is it true that Arya can understand the value for any positive integer x?
Note, that means the remainder of x after dividing it by y.
Input
The first line of the input contains two integers n and k (1 ≤ n, k ≤ 1 000 000) — the number of ancient integers and value k that is chosen by Pari.
The second line contains n integers c_1, _c_2, …, _c__n (1 ≤ c__i ≤ 1 000 000).
Output
Print "Yes" (without quotes) if Arya has a winning strategy independent of value of x, or "No" (without quotes) otherwise.
Example
Input
4 5
2 3 5 12
Output
Yes
Input
2 7
2 3
Output
No
题意:给定N,K。输入N个ni,表示已知X%ni的值,有了N组这样的剩余系,问是否X%K的值唯一。
思路:求出Lcm(ni),若Lcm(ni)%K==0,则唯一。
原因:因为中国剩余定理:ans=Σ(Ai*Ni*Mi)%N,而N就是Lcm(ni)。如果N是K的倍数,那么先%N,再%K的结果是不变的。
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
ll gcd(ll a,ll b)
{
if(b==) return a;
return gcd(b,a%b);
}
int main()
{
ll N,K,x,res=;
scanf("%lld%lld",&N,&K);
for(int i=;i<=N;i++){
scanf("%lld",&x);
res=x/gcd(x,res)*res%K;
}
if(res%K==) printf("Yes\n");
else printf("No\n");
return ;
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章