B. Remainders Game
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

#### Hint

Assume the answer of a test is No. There must exist a pair of integers x1 and x2 such that both of them have the same remainders after dividing by any ci, but they differ in remainders after dividing by k. Find more facts about x1 and x2!

#### Solution

Consider the x1 and x2 from the hint part. We have x1 - x2 ≡ 0 () for each 1 ≤ i ≤ n.

So:

We also have  (). As a result:

We've found a necessary condition. And I have to tell you it's also sufficient!

Assume , we are going to prove there exists x1, x2 such that x1 - x2 ≡ 0 () (for each 1 ≤ i ≤ n), and  ().

A possible solution is x1 = lcm(c1, c2, ..., cn) and x2 = 2 × lcm(c1, c2, ..., cn), so the sufficiency is also proved.

So you have to check if lcm(c1, c2, ..., cn) is divisible by k, which could be done using prime factorization of k and ci values.

For each integer x smaller than MAXC, find it's greatest prime divisor gpdx using sieve of Eratosthenes in .

Then using gpd array, you can write the value of each coin as p1q1p2q2...pmqm where pi is a prime integer and 1 ≤ qi holds. This could be done in  by moving from ci to  and adding gpdci to the answer. And you can factorize k by the same way. Now for every prime p that , see if there exists any coin i that the power of p in the factorization of ci is not smaller than the power of p in the factorization of k.

Complexity is .

x1-x2≡0(mod ci)----->lcm(c1,c2,..,cn)|x1-x2

x1-x2!≡0(mod k)

//
//  main.cpp
//  cf687b
//
//  Created by Candy on 9/20/16.
//

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
;
,f=;
; c=getchar();}
+c-'; c=getchar();}
return x*f;
}
int n,k,c[N];
bool check(int a){
;i<=n;i++) ) ;
;
}
int main(int argc, const char * argv[]) {
;i<=k;i++){
;
) a*=i,k/=i;
&&!check(a)){printf(;}
}
printf("Yes");
;
}

## Codeforces 687B. Remainders Game[剩余]的更多相关文章

1. codeforces 687B - Remainders Game 数学相关（互质中国剩余定理）

题意:给你x%ci=bi(x未知),是否能确定x%k的值(k已知) ——数学相关知识: 首先:我们知道一些事情,对于k,假设有ci%k==0,那么一定能确定x%k的值,比如k=5和ci=20,知道x% ...

2. CodeForces 687B Remainders Game

数论. 如果$x$不唯一,假设存在两个解,较大的为${x_1}$,较小的为${x_2}$. 那么, \$\left\{ {\begin{array}{*{20}{c}}{{x_1}\% {c_i} = ...

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

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

4. Codeforces Educational Codeforces Round 5 E. Sum of Remainders 数学

E. Sum of Remainders 题目连接: http://www.codeforces.com/contest/616/problem/E Description The only line ...

5. codeforces 360 D - Remainders Game

D - Remainders Game Description Today Pari and Arya are playing a game called Remainders. Pari choos ...

6. codeforces 616E Sum of Remainders (数论，找规律）

E. Sum of Remainders time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

7. Educational Codeforces Round 5 E. Sum of Remainders (思维题)

题目链接:http://codeforces.com/problemset/problem/616/E 题意很简单就不说了. 因为n % x = n - n / x * x 所以答案就等于 n * m ...

8. Codeforces 616E - Sum of Remainders

616E Sum of Remainders Calculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + - + n mod m. As ...

9. codeforces 616E. Sum of Remainders 数学

题目链接 给两个数n, m. 求n%1+n%2+.......+n%m的值. 首先, n%i = n-n/i*i, 那么原式转化为n*m-sigma(i:1 to m)(n/i*i). 然后我们可以发 ...

## 随机推荐

1. MySQL PXC构建一个新节点只需IST传输的方法

需求场景:原有的pxc环境数据量已经比较大,新买的服务器要加入此集群中,如何让其用IST的方式传输,而不是SST. PXC传输数据有两种方式: IST: Incremental State Trans ...

2. 使用PhoneGap搭建一个山寨京东APP

为什么要写一个App 首先解释下写出来的这个App,其实无任何功能,只是用HTML和CSS模仿JD移动端界面写的一个适配移动端的Web界面.本篇主要内容是介绍如何使用PhoneGap把开发出来的mob ...

3. Aspect Oriented Programming using Interceptors within Castle Windsor and ABP Framework AOP

http://www.codeproject.com/Articles/1080517/Aspect-Oriented-Programming-using-Interceptors-wit Downl ...

4. ubuntu-15.04-server-i386.iso 安装 Oracle 11gR2 数据库

特点: 需要重新安装老版本的 libaio1_0.3.109-2ubuntu?_i386.deb.默认的libaio库有问题,和其默认libaio的编译方式有关! 默认的gcc 4.9 需要使用 -W ...

our project use hive 0.10 , and in the hiveql , we need use addMonths function builtin in hive-0.11. ...

6. 通过Profiles查看create语句的执行时间消耗 (转)

一,查看profiles的状态值   1,查看profiles是否已经打开了,默认是不打开的.   mysql> show profiles;   Empty set (0.02 sec) my ...

7. 用c#读取文件内容中文是乱码的解决方法：