B. Remainders Game(扩展中国剩余定理)

https://codeforces.com/problemset/problem/687/B


给一堆数字,若已知xmod(这些数字中每一个),问能不能知道xmodk.知道就是yes,不知道就是no.

思路:扩展中国剩余定理的性质应用。

扩展中国剩余定理讲解部分来自:https://www.luogu.com.cn/blog/ShadderLeave/5days-equiv-from-beginner-to-killer

根据EXCRT可得,有解的情况只能是x是这些数lcm的因数。所以判x能否被lcm整除就可以了。

由于数太大,代码上注意求出lcm后%k,同时如果已经是因数了,直接break;

 

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e6+100;
typedef long long LL;
LL c[maxn];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL n,k;cin>>n>>k;
  for(LL i=1;i<=n;i++) cin>>c[i];
  LL ans=c[1];
  for(LL i=1;i<=n-1;i++)
  {
  	if(ans%k==0) 
	{
		ans=ans%k;
		break;
	}
  	LL tmp=c[i]/__gcd(c[i],c[i+1])*c[i+1]%k;//注意modk 
  	ans=tmp;
	c[i+1]=tmp;
  }
  if(ans%k==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
return 0;
}
 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值