码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces 360 D - Remainders Game

时间:2016-07-16 00:21:22      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

    D - Remainders Game

 

Description

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 numbersc1,

c2, ..., cn 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 c1, c2, 

..., cn (1 ≤ ci ≤ 1 000 000).

Output

Print "Yes" (without quotes) if Arya has a winning strategy independent

of value of x, or "No" (without quotes) otherwise.

Sample Input

Input
4 5
2 3 5 12
Output
Yes
Input
2 7
2 3
Output
No

题意:给定n,k,和n个ci。你可以知道x%ci,问是否能确定x%k.
分析:根据中国剩余定理问题就相当于要确定 C 数组整体的最小公倍数 lcm(c)
是否是 K 的倍数,如果是,则能确定输出 yes,否则输出 no.
#include <iostream>
#include<cstdio>
#define LL long long
using namespace std;
int a;
int gcd(LL a,LL b)
{
    return b?gcd(b,a%b):a;
}
int main()
{
    LL n,k,lcm=1;
   scanf("%lld%lld", &n, &k);
     for(int i=0;i<n;i++)
     {
           scanf("%lld", &a);
          lcm = lcm / gcd(lcm, a) * a % k;
    }
    if(lcm%k==0)  printf("Yes\n");
    else      printf("No\n");
    return 0;
}

 

 

codeforces 360 D - Remainders Game

标签:

原文地址:http://www.cnblogs.com/fenhong/p/5674817.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!