D. Remainders Game

题目连接:

http://www.codeforces.com/contest/688/problem/D

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 numbers c1, 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

4 5

2 3 5 12

Sample Output

Yes

Hint

题意

给你k和n

你现在想要知道x,但是人家不告诉你

给你n个ci,表示你可以知道x%ci

问你能不能唯一确定x

题解

首先,根据剩余定理,如果我们想知道x%m等于多少,当且仅当我们知道x%m1,x%m2..x%mr分别等于多少,其中m1m2...mr=m,并且mi相互互质,即构成独立剩余系。令m的素数分解为m=p1k1*p2k2...*prkr,如果任意i,都有piki的倍数出现在集合中,那么m就能被猜出来。

这个问题等价于问LCM(ci)%m是否等于0

所以只要求出LCM(ci)即可,不过要边求lcm,边和m取gcd,防止爆int

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+6;
int n;
long long k,c[maxn];
long long gcd(long long a,long long b){
if(b==0)return a;
return gcd(b,a%b);
}
long long lcm(long long a,long long b){
return a*b/gcd(a,b);
}
int main(){
scanf("%d",&n);
scanf("%lld",&k);
long long tmp = 1;
for(int i=1;i<=n;i++)
{
scanf("%lld",&c[i]);
tmp=lcm(tmp,c[i]);
tmp=gcd(tmp,k);
if(tmp==k){
printf("Yes\n");
return 0;
}
}
printf("No\n");
}

Codeforces Round #360 (Div. 2) D. Remainders Game 数学的更多相关文章

  1. Codeforces Round #360 (Div. 2) D. Remainders Game 中国剩余定理

    题目链接: 题目 D. Remainders Game time limit per test 1 second memory limit per test 256 megabytes 问题描述 To ...

  2. Codeforces Round #360 (Div. 2) D. Remainders Game

    D. Remainders Game time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  3. Codeforces Round #360 (Div. 1) D. Dividing Kingdom II 暴力并查集

    D. Dividing Kingdom II 题目连接: http://www.codeforces.com/contest/687/problem/D Description Long time a ...

  4. Codeforces Round #360 (Div. 2) C. NP-Hard Problem 水题

    C. NP-Hard Problem 题目连接: http://www.codeforces.com/contest/688/problem/C Description Recently, Pari ...

  5. Codeforces Round #360 (Div. 2) B. Lovely Palindromes 水题

    B. Lovely Palindromes 题目连接: http://www.codeforces.com/contest/688/problem/B Description Pari has a f ...

  6. Codeforces Round #360 (Div. 2) A. Opponents 水题

    A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...

  7. Codeforces Round #360 (Div. 1)A (二分图&dfs染色)

    题目链接:http://codeforces.com/problemset/problem/687/A 题意:给出一个n个点m条边的图,分别将每条边连接的两个点放到两个集合中,输出两个集合中的点,若不 ...

  8. Codeforces Round #360 (Div. 1) D. Dividing Kingdom II 并查集求奇偶元环

    D. Dividing Kingdom II   Long time ago, there was a great kingdom and it was being ruled by The Grea ...

  9. Codeforces Round #360 (Div. 2) E. The Values You Can Make DP

    E. The Values You Can Make     Pari wants to buy an expensive chocolate from Arya. She has n coins, ...

随机推荐

  1. Linux内核触摸屏驱动--多点触摸 【转】

      转自:http://blog.chinaunix.net/uid-24227137-id-3127126.html 简介 为了使用功能强大的多点触控设备,就需要一种方案去上报用户层所需的详细的手指 ...

  2. checkbox 全选和取消

    //全选 $("#checkall").click(function () { if (this.checked) { //如果当前点击的多选框被选中 $('input[type= ...

  3. ajax代码示例

    function loadXMLDoc(idName,url,sendOut) { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, ...

  4. Jenkins无法安装插件或首次安装插件界面提示Offline

    一.首先点击系统管理 二.点击插件管理 三.选择高级管理 四.将升级站点中的https改成http即可

  5. 关于move

    procedure TForm4.Button1Click(Sender: TObject); var //动态数组 bytes1,bytes2: TBytes; //静态数组 bytes3,byte ...

  6. java 学习网站

    http://how2j.cn/  教学网站 慕课视频下载网站 http://www.feemic.cn/mooc //慕课搜索和下载的网站http://www.soshoulu.com/tools/ ...

  7. matlab转python

    最近在做把matlab代码转成python代码,没有用过matlab,python也只是局限于爬虫,所以.... matlab与python最大的不同是,matlab的下标是从1开始的,python和 ...

  8. putIfAbsent

    public static HashSet<Long> getOrInitHashMapCacheValue(Long mId){ // HashSet<Long> set = ...

  9. OBJECT_ID()的使用方法

    数据库中每个对像都有一个唯一的ID值,用Object_name(id)可以根据ID值得到对像的名称,object_id(name)可以根据对像名称得到对象的ID object_id()只能返回用户创建 ...

  10. Java编程思想第四版第二章练习题答案

    练习1:创建一个类,它包含一个int域和一个char域,它们都没有被初始化.将他们的值打印出来,以验证Java执行了默认初始化 public class JavaThinking { private ...