• 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;
    }
    
    
    
     
  • 相关阅读:
    API设计和微服务
    Eolinker与API文档
    mysql由浅入深探究(一)----数据库简介与mysql安装
    HttpSession详解
    运行python程序的时候不停的输出destroy和clean信息
    ERROR 1221 (HY000): Incorrect usage of UNION and ORDER BY
    GitLab / Github如何修改默认主分支
    mac安装pyenv和遇到的奇怪问题
    Python Pytest装饰器@pytest.mark.parametrize详解
    gitLab项目左侧找不到”setting"选项链接
  • 原文地址:https://www.cnblogs.com/fenhong/p/5674817.html
Copyright © 2020-2023  润新知