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.

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<cmath>
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
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 ;
}

CodeForces-668D:Remainders Game (中国剩余定理||理解)的更多相关文章

  1. codeforces 688D D. Remainders Game(中国剩余定理)

    题目链接: D. Remainders Game time limit per test 1 second memory limit per test 256 megabytes input stan ...

  2. Educational Codeforces Round 16 D. Two Arithmetic Progressions (不互质中国剩余定理)

    Two Arithmetic Progressions 题目链接: http://codeforces.com/contest/710/problem/D Description You are gi ...

  3. 逆元 exgcd 费马小定理 中国剩余定理的理解和证明

    一.除法取模逆元 如果我们要通过一个前面取过模的式子递推出其他要取模的式子,而递推式里又存在除法 那么一个很尴尬的事情出现了,假如a[i-1]=100%31=7 a[i]=(a[i-1]/2)%31 ...

  4. Remainders Game (中国剩余定理)

    题意:已知k和一个集合C={c1,c2,c3....cn},问是否有满足集合C的中国剩余定理的解x,使x%k的值唯一确定. 数学知识: #include<iostream> #includ ...

  5. E - Two Arithmetic Progressions(CodeForces - 710D)(拓展中国剩余定理)

    You are given two arithmetic progressions: a1k + b1 and a2l + b2. Find the number of integers x such ...

  6. 中国剩余定理(Chinese Remainder Theorem)

    我理解的中国剩余定理的含义是:给定一个数除以一系列互素的数${p_1}, \cdots ,{p_n}$的余数,那么这个数除以这组素数之积($N = {p_1} \times  \cdots  \tim ...

  7. POJ 1006 - Biorhythms (中国剩余定理)

    B - Biorhythms Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Subm ...

  8. 数论F - Strange Way to Express Integers(不互素的的中国剩余定理)

    F - Strange Way to Express Integers Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format: ...

  9. Bell(hdu4767+矩阵+中国剩余定理+bell数+Stirling数+欧几里德)

    Bell Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status  ...

随机推荐

  1. 关于 最短路条数 和 边不可重复最短路条数问题 /hdu3599(边不可重复最短路)

    原先一直在做一道省赛题,由于题意错误理解成球最短路条数,误打误撞敲了最短路条数,又发现hdu3599(多校)求边不可重复最短路条数.下面说说俩种问题解法: 最短路条数: 求一个图一共一几条最短路径,思 ...

  2. rsync同步文件

    rsync中的参数 -r 是递归 -l 是链接文件,意思是拷贝链接文件:-p 表示保持文件原有权限:-t 保持文件原有时间:-g 保持文件原有用户组:-o 保持文件原有属主:-D 相当于块设备文件: ...

  3. 阿里云***(java应用)

    阿里云***(FQ)实战 前言 ​ 因为公司涉及国外业务,依赖于google的map服务,生产环境我们使用的是亚马逊服务器,所以访问google地图没问题,但是国内的开发.测试环境,使用的是阿里云,想 ...

  4. 转:给 Android 开发者的 RxJava 详解

    转自:  http://gank.io/post/560e15be2dca930e00da1083 评注:多图解析,但是我还是未看懂. 前言 我从去年开始使用 RxJava ,到现在一年多了.今年加入 ...

  5. window7_64安装STAF

    1.       安装包下载 从http://sourceforge.net/projects/staf/files/staf/V3.4.17/下载所需安装包,有Windows.Linux.Solar ...

  6. Android——ListView优化

    1.ListView基本概念 列表显示需要三个元素: ListView:用来展示列表的View. 适配器:用来把数据映射到ListView上 数据:具体的将被映射的字符串,图片或基本组件 适配器类型分 ...

  7. 整理对Spark SQL的理解

    Catalyst Catalyst是与Spark解耦的一个独立库,是一个impl-free的运行计划的生成和优化框架. 眼下与Spark Core还是耦合的.对此user邮件组里有人对此提出疑问,见m ...

  8. Intel graphics processing units

    http://en.wikipedia.org/wiki/Comparison_of_Intel_graphics_processing_units Comparison of Intel graph ...

  9. mybatis 动态curd

    xml <select id="selectByCondition" parameterType="com.oracle.pojo.Student" re ...

  10. System V IPC相关函数

    System V IPC 将一个已保存的路径名和一个整数标识符转换成一个key_t值,称为IPC键key_t:System V IPC(System V消息队列.System V信号量.System ...