Codeforces Round # (Div. 2) D. Remainders Game (Chinese remainder theorem)

Source: Internet
Author: User
D. remainders Game

Today Pari and Arya are playing a game called remainders.

Pari chooses, positive integer  x  and  K , and tells Arya  k  but not  x . Arya has to find the value . There Are  n  ancient numbers  c Span class= "Lower-index" >1, C 2, ..., c N  and Pari have to tell Arya  if Arya wants. Given  K  and The ancient values, tell us if Arya have a winning strategy Independe NT of value Of  x  or not. Formally, is it true this Arya can understand the value  for any positive integer  x ?

Note, that's means the remainder of x after dividing it by y.

Input

The first line of the input contains the integers n and k (1≤ n, K ≤1 -the number of ancient integers and value k that's chosen by Pari.

The second line contains n integers c1, C2, ..., c n (1≤ ci ≤1).

Output

Print "Yes" (without quotes) if Arya has a winning strategy independent of value of x, or "No" (Witho UT quotes) otherwise.

Examplesinput
4 5
2 3 5 12
Output
Yes
Input
2 7
2 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. For example 1 and 7 has the same remainders after dividing by 2 and 3, but they differ in remainders afte R dividing by 7.

#include <cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<map>#include<iostream>using namespacestd;#definell Long Longll LCM;Const intMAXN = 1e6 +Ten; ll GETLCM (ll A, ll b) {returnA/__GCD (A, b) *b;} ll P[MAXN];intMain () {ll n, K;  while(~SCANF ("%i64d%i64d", &n, &k)) { for(inti =1; I <= N; i++) scanf ("%i64d", &P[i]); ll LCM=1; intFlag =0;  for(inti =1; I <= N; i++) {LCM=GETLCM (LCM, p[i]); LCM= LCM%K; if(LCM = =0) {puts ("Yes"); Flag=1;  Break; }        } if(!flag) puts ("No"); }}

Codeforces Round #(Div. 2) D. Remainders Game (Chinese remainder theorem)

Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.