zoukankan      html  css  js  c++  java
  • codeforces 360 D

        D - Remainders Game

    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 numbersc1,

    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

    Input
    4 5
    2 3 5 12
    Output
    Yes
    Input
    2 7
    2 3
    Output
    No

    题意:给定n,k,和n个ci。你可以知道x%ci,问是否能确定x%k.
    分析:根据中国剩余定理问题就相当于要确定 C 数组整体的最小公倍数 lcm(c)
    是否是 K 的倍数,如果是,则能确定输出 yes,否则输出 no.
    #include <iostream>
    #include<cstdio>
    #define LL long long
    using namespace std;
    int a;
    int gcd(LL a,LL b)
    {
        return b?gcd(b,a%b):a;
    }
    int main()
    {
        LL n,k,lcm=1;
       scanf("%lld%lld", &n, &k);
         for(int i=0;i<n;i++)
         {
               scanf("%lld", &a);
              lcm = lcm / gcd(lcm, a) * a % k;
        }
        if(lcm%k==0)  printf("Yes
    ");
        else      printf("No
    ");
        return 0;
    }
    
    
    
     
  • 相关阅读:
    2019-2020-1 20191312《信息安全专业导论》第十二周学习总结
    GPG
    2019-2020-1 20191312《信息安全专业导论》第十一周学习总结
    wireshark
    ssh
    Nmap
    2019-2020-1 《python程序设计》20192428魏来 综合实践报告
    20192428 魏来 2019-2020《Python程序设计》 实验三 报告
    20192428 实验二《Python程序设计》实验报告
    20192428 实验一《Python程序设计》实验报告
  • 原文地址:https://www.cnblogs.com/fenhong/p/5674817.html
Copyright © 2011-2022 走看看