• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
dwtfukgv
博客园    首页    新随笔    联系   管理    订阅  订阅
CodeForces 687B Remainders Game(数学,最小公倍数)

题意:给定 n 个数,一个数 k,然后你知道一个数 x 取模这个 n 个的是几,最后问你取模 k,是几。

析:首先题意就看了好久,其实并不难,我们只要能从 n 个数的最小公倍数是 k的倍数即可,想想为什么。如果考虑用 k 除以最大公约数是错误的,

因为可能存在相同的因数,这个是不能算的。

代码如下:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>
#include <cmath>

using namespace std;
typedef long long LL;

LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b);  }//最大公约数

LL lcm(LL a, LL b){ return a * b / gcd(a, b);  }//最小公倍数

int main(){
    int n;  LL k, x;
    scanf("%d %lld", &n, &k);
    LL ans = 1;
    for(int i = 0; i < n; ++i){
        scanf("%lld", &x);
        ans = lcm(ans, x) % k;
    }
    if(!ans)  puts("Yes");//如果能整除就是可以的
    else   puts("No");
    return 0;
}

 

posted on 2016-07-06 10:28  dwtfukgv  阅读(263)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3