Codeforces Round #360 (Div. 1)B - Remainders Game

链接:http://codeforces.com/contest/687/problem/B

题意:给定n个整数a[i]和一个k,对于每一个整数x会有一个数组{x%a[1],x%a[2]....,x%a[n]},要求判断是否能根据一个数组判断出x%k。

分析:我们可以将数组的每一位分开看,显然a[i]的循环节是a[i],那么我们就能知道整体的循环节即最小公倍数lcm。那么我们只需要判断lcm能否整除k。

代码:

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=1000010;
const int MAX=1000000100;
const int mod=100000000;
const int MOD1=1000000007;
const int MOD2=1000000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=1000000007;
const int INF=1000000010;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned long long ull;
ll a[N];
ll gcd(ll a,ll b) {
    return b==0 ? a:gcd(b,a%b);
}
int main()
{
    int i,n;
    ll k,g,lcm=1;
    scanf("%d%I64d", &n, &k);
    for (i=1;i<=n;i++) {
        scanf("%I64d", &a[i]);
        lcm=lcm/gcd(lcm,a[i])*a[i];
        lcm=gcd(lcm,k);
        if (lcm==k) break ;
    }
    if (k==lcm) printf("Yes\n");
    else printf("No\n");
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值