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

D. Remainders Game

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.

Examples

input

4 52 3 5 12

output

Yes

input

2 72 3

output

No

Note

In the first sample, Arya can understand  because 5 is one of the ancient numbers.

In the second sample, Arya can‘t be sure what  is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7.

#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <map>
#include <iostream>
using namespace std;
#define ll long long
ll lcm;
const int maxn = 1e6 + 10;
ll getlcm(ll a, ll b) {
    return a / __gcd(a, b) * b;
}

ll p[maxn];

int main() {
    ll n, k;
    while(~scanf("%I64d %I64d", &n, &k)) {
        for(int i = 1; i <= n; i++) scanf("%I64d", &p[i]);
        ll lcm = 1;
        int flag = 0;
        for(int i = 1; i <= n; i++) {
            lcm = getlcm(lcm, p[i]);
            lcm = lcm % k;
            if(lcm == 0) {
                puts("Yes");
                flag = 1;
                break;
            }
        }
        if(!flag) puts("No");
    }
}
时间: 2024-10-06 06:37:26

Codeforces Round #360 (Div. 2) D. Remainders Game(中国剩余定理)的相关文章

Codeforces Round #360 (Div. 2) D 数学推导 E dp

Codeforces Round #360 (Div. 2) A  == B  水,但记一下: 第 n 个长度为偶数的回文数是  n+reverse(n). C    dfs 01染色,水 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i

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

题目链接:http://codeforces.com/problemset/problem/687/A 题意:给出一个n个点m条边的图,分别将每条边连接的两个点放到两个集合中,输出两个集合中的点,若不可能则输出-1: 思路:通过画图我们不难发现,图中没有出现长度为奇数的环则是可行的,反之则是不行的.那么现在我们只需判断有木有长度为偶数的环即可. 对于这点我们可以直接用dfs搜索+染色,对于当前标记为1的点,我们将其所有儿子标记为2, 对于当前标记为2的点,将其所有儿子标记为1,若出现某个节点的标

Codeforces Round #360 (Div. 2) C D E

每次AB秒出 到了C难度陡然上升...翻译都弄不懂... C 给出一张图 找出两个点的覆盖集(覆盖集是指这图中每条边都有至少一个点在这个点集里面) 并且两个点集没有交集 英文很难看懂...就是二分图的判定 看看这张图是不是二分图 输出两边的点 不是二分图输出-1 坑点是这是special judge 但是题目没说 每个联通块都要进行一次bfs 那些独立点可以不输出也可以随意分配 D 给出k与n个数ci 我们知道一个未知的数x%ci的数 问能不能求出x%k的数 可以利用中国剩余定理来解 如果我们知

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

题意:给出一个无向图,问是否可以是二分图, 思路:染色就行了,二分图又称作二部图,是图论中的一种特殊模型. 设G=(V,E)是一个无向图,如果顶点V可分割为两个互不相交的子集(A,B),并且图中的每条边(i,j)所关联的两个顶点i和j分别属于这两个不同的顶点集(i in A,j in B),则称图G为一个二分图. 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e5+10; 4 struct node{ 5 int

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 Great Arya and Pari The Great. These two had some problems about the numbers they like, so they decided to divide the great kingdom between themselves. The

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我