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, ...
 
随机推荐
- java 判断上传文件大小
			
/** * 判断文件大小 * * @param file * 文件 * @param size * 限制大小 * @param unit * 限制单位(B,K,M,G) * @return */ pu ...
 - ProtocolBuffer 使用及 一些坑
			
Protocol Buffers,是Google公司开发的一种数据描述语言,类似于XML能够将结构化数据序列化,可用于数据存储.通信协议等方面. ProtocolBuffer的优势 跨平台: Prot ...
 - Ibatis.Net 各类的作用说明学习(三)
			
Ibatis中,加载.分析配置及映射文件是在创建SqlMapper实例的时候进行的,另外对数据库的操作,也是在SqlMapper实例上调用方法来完成.创建SqlMapper的实例的方式是: ISqlM ...
 - Google Chrome中的高性能网络-[译]《转载》
			
以下内容是"The Performance of Open Source Applications" (POSA)的草稿, 也是The Architecture of Open S ...
 - GLOBAL_NAMES参数研究
			
最近在配置Stream时,发现必须要把GLOBAL_NAMES参数的指设置为TRUE,具体原因为何不知.但是发现在设置了该参数之后,数据库每天的物化视图刷新出现了问题.之后查明原因,是DBLINK出现 ...
 - nginx + tomcat 集群记录
			
昨天晚写的时候已经下班了.时间紧迫.写的略简! 昨天说过.接到部署的任务之后.首先想到的是apache httpserver 毕竟pache.我们接触的比较多!然而部署之后遇到了很多问题.比如apac ...
 - Fix Valgrind's must-be-redirected error in Gentoo
			
Last week, I tried to use Valgrind to identify potential memory related bugs, since segmentation fau ...
 - [Torch]的安装
			
1 安装Torch 本文介绍Torch7的安装方法,因为本人安装Torch前安装了caffe,所以可能CUDA.cudnn.Blas等Torch可能需要用来的库的安装就不再重复介绍了,相关依赖出现问题 ...
 - C# 在RichTextBox根据内容自动调整高度
			
private void richTextBox1_ContentsResized(object sender, ContentsResizedEventArgs e) { richTextB ...
 - #Git 详细中文安装教程
			
Step 1 Information 信息 Please read the following important information before continuing 继续之前,请阅读以下重要 ...