Codeforces Round #360 (Div. 2) D. Remainders Game 数学
D. Remainders Game
题目连接:
http://www.codeforces.com/contest/688/problem/D
Description
Today Pari and Arya are playing a game called Remainders.
Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value . There are n ancient numbers c1, c2, ..., cn and Pari has to tell Arya if Arya wants. Given k and the ancient values, tell us if Arya has a winning strategy independent of value of x or not. Formally, is it true that Arya can understand the value for any positive integer x?
Note, that means the remainder of x after dividing it by y.
Input
The first line of the input contains two integers n and k (1 ≤ n, k ≤ 1 000 000) — the number of ancient integers and value k that is chosen by Pari.
The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 1 000 000).
Output
Print "Yes" (without quotes) if Arya has a winning strategy independent of value of x, or "No" (without quotes) otherwise.
Sample Input
4 5
2 3 5 12
Sample Output
Yes
Hint
题意
给你k和n
你现在想要知道x,但是人家不告诉你
给你n个ci,表示你可以知道x%ci
问你能不能唯一确定x
题解
首先,根据剩余定理,如果我们想知道x%m等于多少,当且仅当我们知道x%m1,x%m2..x%mr分别等于多少,其中m1m2...mr=m,并且mi相互互质,即构成独立剩余系。令m的素数分解为m=p1k1*p2k2...*prkr,如果任意i,都有piki的倍数出现在集合中,那么m就能被猜出来。
这个问题等价于问LCM(ci)%m是否等于0
所以只要求出LCM(ci)即可,不过要边求lcm,边和m取gcd,防止爆int
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+6;
int n;
long long k,c[maxn];
long long gcd(long long a,long long b){
if(b==0)return a;
return gcd(b,a%b);
}
long long lcm(long long a,long long b){
return a*b/gcd(a,b);
}
int main(){
scanf("%d",&n);
scanf("%lld",&k);
long long tmp = 1;
for(int i=1;i<=n;i++)
{
scanf("%lld",&c[i]);
tmp=lcm(tmp,c[i]);
tmp=gcd(tmp,k);
if(tmp==k){
printf("Yes\n");
return 0;
}
}
printf("No\n");
}
Codeforces Round #360 (Div. 2) D. Remainders Game 数学的更多相关文章
- Codeforces Round #360 (Div. 2) D. Remainders Game 中国剩余定理
题目链接: 题目 D. Remainders Game time limit per test 1 second memory limit per test 256 megabytes 问题描述 To ...
- Codeforces Round #360 (Div. 2) D. Remainders Game
D. Remainders Game time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #360 (Div. 1) D. Dividing Kingdom II 暴力并查集
D. Dividing Kingdom II 题目连接: http://www.codeforces.com/contest/687/problem/D Description Long time a ...
- Codeforces Round #360 (Div. 2) C. NP-Hard Problem 水题
C. NP-Hard Problem 题目连接: http://www.codeforces.com/contest/688/problem/C Description Recently, Pari ...
- Codeforces Round #360 (Div. 2) B. Lovely Palindromes 水题
B. Lovely Palindromes 题目连接: http://www.codeforces.com/contest/688/problem/B Description Pari has a f ...
- Codeforces Round #360 (Div. 2) A. Opponents 水题
A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...
- Codeforces Round #360 (Div. 1)A (二分图&dfs染色)
题目链接:http://codeforces.com/problemset/problem/687/A 题意:给出一个n个点m条边的图,分别将每条边连接的两个点放到两个集合中,输出两个集合中的点,若不 ...
- Codeforces Round #360 (Div. 1) D. Dividing Kingdom II 并查集求奇偶元环
D. Dividing Kingdom II Long time ago, there was a great kingdom and it was being ruled by The Grea ...
- Codeforces Round #360 (Div. 2) E. The Values You Can Make DP
E. The Values You Can Make Pari wants to buy an expensive chocolate from Arya. She has n coins, ...
随机推荐
- mysql5.7半自动同步设置【转】
mysql的主从复制主要有3种模式: a..主从同步复制:数据完整性好,但是性能消耗高 b.主从异步复制:性能消耗低,但是容易出现主从数据唯一性问题 c.主从半自动复制:介于上面两种之间.既能很好的保 ...
- Codeforces Round #504 D. Array Restoration
Codeforces Round #504 D. Array Restoration 题目描述:有一个长度为\(n\)的序列\(a\),有\(q\)次操作,第\(i\)次选择一个区间,将区间里的数全部 ...
- ubuntu使用百度云盘插件
Firefox 插件地址 https://addons.mozilla.org/zh-CN/firefox/addon/baidu-pan-exporter/ 安装后重启Firefox,然后百度云下载 ...
- Flask:cookie 和 session (0.1)
Windows 10家庭中文版,Python 3.6.4,Flask 1.0.2 Cookie是什么?有什么用? 某些网站为了辨别用户身份.进行 session 跟踪而储存在用户本地终端上的数据(通常 ...
- QUnit 实践一
项目准备启用Qunit, 先来尝试一下. 不说废话,上代码: <!DOCTYPE HTML> <html> <head> <meta http-equiv=& ...
- docker修改docker0 mtu
由于docker宿主机设置了mtu造成docker镜像中mtu和宿主机mtu不匹配,大包后网络不同.所以需要设置docker0的mtu. 1.修改docker.service vi /usr/lib/ ...
- Docker - CentOS安装Docker
如果要在CentOS下安装Docker容器,必须是CentOS 7 (64-bit).CentOS 6.5 (64-bit) 或更高的版本,并要求 CentOS 系统内核高于 3.10. uname ...
- table中的td等长(不随内容大小变化)
使用的table时候发现td的长度是随着内容的大小而变化的,但是有的时候我们不希望这样.想要td等长可以在 tbale中加上 style=“table-layout:fixed” ...
- Spring框架的基本使用(IOC部分)
Spring是一个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架. Spring的好处 1.方便解耦,简化开发: Spring就是一个大工厂,专门负责生成Bean,可以将所有对象创建和依赖关 ...
- 2017 MoveIt!更新 ros indigo
First MoveIt! Update in 2017. Using it on NEXTAGE pt.1 2017 MoveIt! update pt.2; Stopping motion on ...