• codeforces#687 B. Remainders Game


    题意:给出n个数,和一个数p,问你在知道 x%ai  的情况下,能不能确定x%p的值

    结论:当n个数的最小公倍数是p的倍数时,可以确定

    代码:

    #include <bits/stdc++.h>
    #define ll long long
    using namespace std;
    const int maxn=1e6+10;
    vector<int>ve;
    int n,p;
    int main()
    {
        scanf("%d %d",&n,&p);
        for(int i=2; i*i<=p; i++)
        {
            if(p%i==0)
            {
                ll res=i;
                while(p%(res*i)==0&&p>=(res*i))
                    res*=i;
                p/=res;
                ve.push_back(res);
            }
        }
        if(p!=1)ve.push_back(p);
        for(int i=1; i<=n; i++)
        {
            int x;
            scanf("%d",&x);
            for(int i=0; i<ve.size(); i++)
            {
                if(ve[i]==0)continue;
                if(x%ve[i]==0)ve[i]=0;
            }
        }
        for(int i=0; i<ve.size(); i++)
            if(ve[i]!=0)
            {
                cout<<"No"<<endl;
                return 0;
            }
        cout<<"Yes"<<endl;
        return 0;
    }
    

      

  • 相关阅读:
    Count on a tree
    图论1 1009
    DP2 1008
    DP1 1008
    NOIP 模拟 1006
    2019 CSP-S 初赛退役记
    9.13——TEST NOIP模拟测试
    [洛谷P2387][NOI2014]魔法森林
    [洛谷P2596][ZJOI2006]书架
    [BZOJ4241]历史研究
  • 原文地址:https://www.cnblogs.com/carcar/p/10215968.html
Copyright © 2020-2023  润新知