Codeforces 687B. Remainders Game[剩余]
1 second
256 megabytes
standard input
standard output
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.
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).
Print "Yes" (without quotes) if Arya has a winning strategy independent of value of x, or "No" (without quotes) otherwise.
4 5
2 3 5 12
Yes
2 7
2 3
No
In the first sample, Arya can understand because 5 is one of the ancient numbers.
In the second sample, Arya can't be sure what is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7.
题意:有数字x和k,x未知;知道x mod ci的结果,问x mod k是否唯一
官方题解:
Hint
Assume the answer of a test is No. There must exist a pair of integers x1 and x2 such that both of them have the same remainders after dividing by any ci, but they differ in remainders after dividing by k. Find more facts about x1 and x2!
Solution
Consider the x1 and x2 from the hint part. We have x1 - x2 ≡ 0 () for each 1 ≤ i ≤ n.
So:
We also have (
). As a result:
We've found a necessary condition. And I have to tell you it's also sufficient!
Assume , we are going to prove there exists x1, x2 such that x1 - x2 ≡ 0 (
) (for each 1 ≤ i ≤ n), and
(
).
A possible solution is x1 = lcm(c1, c2, ..., cn) and x2 = 2 × lcm(c1, c2, ..., cn), so the sufficiency is also proved.
So you have to check if lcm(c1, c2, ..., cn) is divisible by k, which could be done using prime factorization of k and ci values.
For each integer x smaller than MAXC, find it's greatest prime divisor gpdx using sieve of Eratosthenes in .
Then using gpd array, you can write the value of each coin as p1q1p2q2...pmqm where pi is a prime integer and 1 ≤ qi holds. This could be done in by moving from ci to
and adding gpdci to the answer. And you can factorize k by the same way. Now for every prime p that
, see if there exists any coin i that the power of p in the factorization of ci is not smaller than the power of p in the factorization of k.
Complexity is .
题解前一部分比较好,后面还用筛法太扯了,质因数分解不用判质数
假设有两个x1和x2,如果x mod k不唯一的话则x1和x2满足:
x1-x2≡0(mod ci)----->lcm(c1,c2,..,cn)|x1-x2
x1-x2!≡0(mod k)
那么:
最小的x1-x2就是lcm
代入得lcm!≡0(mod k) 也就是k!|lcm
质因数分解k判断每个质因子是否是某个ci 的约数,如果全是则可以整除,解唯一,一定可以猜出
//
// main.cpp
// cf687b
//
// Created by Candy on 9/20/16.
// Copyright © 2016 Candy. All rights reserved.
// #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e6+;
int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
int n,k,c[N];
bool check(int a){
for(int i=;i<=n;i++) if(c[i]%a==) return ;
return ;
}
int main(int argc, const char * argv[]) {
n=read();k=read();
for(int i=;i<=n;i++) c[i]=read();
for(int i=;i<=k;i++){
int a=;
while(k%i==) a*=i,k/=i;
if(a!=&&!check(a)){printf("No");return ;}
}
printf("Yes");
return ;
}
Codeforces 687B. Remainders Game[剩余]的更多相关文章
- codeforces 687B - Remainders Game 数学相关(互质中国剩余定理)
题意:给你x%ci=bi(x未知),是否能确定x%k的值(k已知) ——数学相关知识: 首先:我们知道一些事情,对于k,假设有ci%k==0,那么一定能确定x%k的值,比如k=5和ci=20,知道x% ...
- CodeForces 687B Remainders Game
数论. 如果$x$不唯一,假设存在两个解,较大的为${x_1}$,较小的为${x_2}$. 那么, $\left\{ {\begin{array}{*{20}{c}}{{x_1}\% {c_i} = ...
- CodeForces 687B Remainders Game(数学,最小公倍数)
题意:给定 n 个数,一个数 k,然后你知道一个数 x 取模这个 n 个的是几,最后问你取模 k,是几. 析:首先题意就看了好久,其实并不难,我们只要能从 n 个数的最小公倍数是 k的倍数即可,想想为 ...
- 【16.56%】【codeforces 687B】Remainders Game
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 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 题目连接: http://www.codeforces.com/contest/688/problem/D Description Today Pari and ...
- Codeforces Educational Codeforces Round 5 E. Sum of Remainders 数学
E. Sum of Remainders 题目连接: http://www.codeforces.com/contest/616/problem/E Description The only line ...
- 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 688D D. Remainders Game(中国剩余定理)
题目链接: D. Remainders Game time limit per test 1 second memory limit per test 256 megabytes input stan ...
随机推荐
- JavaScript学习笔记-实例详解-类(二)
实例详解-类(二) //===给Object.prototype添加只读\不可枚举\不可配置的属性objectId(function(){ Object.defineProperty(Object ...
- 30分钟手把手教你学webpack实战
30分钟手把手教你学webpack实战 阅读目录 一:什么是webpack? 他有什么优点? 二:如何安装和配置 三:理解webpack加载器 四:理解less-loader加载器的使用 五:理解ba ...
- 完美解决AutoCAD2012,AutoCAD2013本身电脑里有NET4.0或以上版本却装不上的问题
适用情况:电脑里本身有NET4.0或4.5版本,并且正确安装.或本身你就装有AutoCAD2013或AutoCAD2012要装AutoCAD2012或AutoCAD2013却装不上的情况 如图1所示. ...
- Android 常用数据适配器ArrayAdapter
接着上篇文章<Android 采用Layout Inflater创建一个View对象>,本文采用常用数据适配器ArrayAdapter 新建项目后,在layout文件夹下新建list_it ...
- TCP/IP 协议难点之一—— IP分片
1 IP协议简单介绍 就个人而言,网络中,抛开网络安全加密这些,就只单单讨论协议本身,比较难的有三个地方: IP分片与重组 TCP滑动窗口与TCP状态的改变 TCP定时器 其实协议本身根据<TC ...
- Charles中如何对https抓包
前言:下面介绍关于Charles中如何对https抓包 1.在默认没有相关设置HTTPS需要设置相关操作的时候,会出现下面的情况: 2.下面就是设置SSL Proxying,然后443是默可用的端口 ...
- win7---远程桌面相关的服务
如果对方连接不到你,请将服务设置为自动,并重启电脑.
- WPF学习之路(十四)样式和模板
样式 实例: <Window.Resources> <Style x:Key="BtnStyle"> <Setter Property=" ...
- Tomcat:基于Apache+Tomcat的集群搭建
根据Tomcat的官方文档说明可以知道,使用Tomcat配置集群需要与其它Web Server配合使用才可以完成,典型的有Apache和IIS. 这里就使用Apache+Tomcat方式来完成基于To ...
- Mysql字符集知识总结
字符集&字符编码方式 字符集(Character set)是多个字符的集合,字符集种类较多,每个字符集包含的字符个数不同,这里的字符可以是英文字符,汉字字符,或者其他国家语言字符. 常见字符集 ...