首页 > 学院 > 开发设计 > 正文

[Codeforces688D]Remainders Game(扩展中国剩余定理)

2019-11-08 01:26:08
字体:
来源:转载
供稿:网友

题目描述

传送门

题解

实际上就是道sb题 不互质的数用扩展中国剩余定理合并的话,实际上最后的模数就是lcm 判断lcm是否是k的倍数即可

代码

#include<algorithm>#include<iostream>#include<cstring>#include<cstdio>#include<cmath>using namespace std;#define LL long long#define N 1000005int n;LL m[N],k;LL gcd(LL a,LL b){ if (!b) return a; else return gcd(b,a%b);}int main(){ scanf("%d%I64d",&n,&k); for (int i=1;i<=n;++i) scanf("%I64d",&m[i]); m[1]%=k; for (int i=2;i<=n;++i) { m[i]=m[i-1]*m[i]/gcd(m[i-1],m[i]); m[i]%=k; } if (!m[n]) puts("Yes"); else puts("No");}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表