【16.56%】【codeforces 687B】Remainders Game
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
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.
Examples
input
4 5
2 3 5 12
output
Yes
input
2 7
2 3
output
No
Note
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 的值
但是只告诉你k以及一系列x % ci;
做法:
根据中国剩余定理:
如果知道了
x % a;
x % b;
x % c;
x % d;
····
且a,b,c,d互质;
那么x % (abcd)就可以确定了;
那么因为要求x % k
所以对k进行质数分解;
各个质数肯定是互质的;
分解成k = p1^k1*p2^k2…pn^kn的形式
然后你还得知道这么一个东西
如果
a 是 b的倍数,即a %b==0
那么
x % a = y1
x % b = y2
那么y2 = y1 % b;
即
x = t1*a+ y1 ···①
x = t2*b + y2
因为a是b的倍数
所以①式总可以写成
x = t1*t3*b + y1的形式
显然y1 再对b取模就是y2了;
回到质数分解后
分解成k = p1^k1*p2^k2…pn^kn的形式
我们想知道
x % p1^k1
x % p2^k2
….
x % pn^kn
这样我们就能知道x %k了
根据上面的分析,我们只要在所给的ci里面找pi^ki的倍数就好了;
如果对于所有的t∈[1..n]总有数字ci是pt^kt的倍数;
因为如果ci是pt^kt的倍数,则x % ci知道了,相应的x%(pt^kt)按照上面的分析也能知道了->(x%ci) % (pt^kt)
既然知道了所有的x%pt^kt
那么就能求出x%k了;
#include <cstdio>
int n, k,cnt = 0;
int num[10000];
bool cover[10000] = { 0 };
int main()
{
//freopen("F:\\rush.txt", "r", stdin);
scanf("%d%d", &n, &k);
for (int i = 2;i <= k;i++)
if ((k%i) == 0)
{
int now = 1;
while ((k%i) == 0)
{
now = now*i;
k /= i;
}
num[++cnt] = now;//存的是p1^k1..pcnt^kcnt
}
for (int i = 1; i <= n; i++)
{
int x;
scanf("%d", &x);
for (int j = 1; j <= cnt; j++)
if (x % num[j] == 0)//如果是的x%pt^kt倍数,那么x%pt^kt就能求出来了
cover[j] = true;
}
for (int j = 1;j <= cnt;j++)
if (!cover[j])
{
puts("NO");
return 0;
}
puts("YES");
return 0;
}
【16.56%】【codeforces 687B】Remainders Game的更多相关文章
- 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...
- 【16.23%】【codeforces 586C】Gennady the Dentist
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 807D】Dynamic Problem Scoring
[题目链接]:http://codeforces.com/contest/807/problem/D [题意] 给出n个人的比赛信息; 5道题 每道题,或是没被解决->用-1表示; 或者给出解题 ...
- 【codeforces 821E】Okabe and El Psy Kongroo
[题目链接]:http://codeforces.com/problemset/problem/821/E [题意] 一开始位于(0,0)的位置; 然后你每次可以往右上,右,右下3走一步; (x+1, ...
- 【81.82%】【codeforces 740B】Alyona and flowers
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【23.39%】【codeforces 558C】Amr and Chemistry
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【42.59%】【codeforces 602A】Two Bases
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【77.78%】【codeforces 625C】K-special Tables
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 【codeforces 755D】PolandBall and Polygon
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- 逻辑与和逻辑或:&& 、||
逻辑或:首先看左边是真还是假(除了那5个都是真),如果为真,返回左边值,如果为假,返回右边的值 逻辑与:和逻辑或相同,先看左边的值是真是假,如果左边为真返回右边的值,左边为假返回左边的值 在两者同时出 ...
- 洛谷—— P1017 进制转换
https://www.luogu.org/problem/show?pid=1017#sub 题目描述 我们可以用这样的方式来表示一个十进制数: 将每个阿拉伯数字乘以一个以该数字所处位置的(值减1) ...
- UVA10006 - Carmichael Numbers(筛选构造素数表+高速幂)
UVA10006 - Carmichael Numbers(筛选构造素数表+高速幂) 题目链接 题目大意:假设有一个合数.然后它满足随意大于1小于n的整数a, 满足a^n%n = a;这种合数叫做Ca ...
- js进阶 12-14 jquery的事件触发函数是哪两个
js进阶 12-14 jquery的事件触发函数是哪两个 一.总结 一句话总结:trigger和triggerHandler 1.trigger传额外参数时候的注意事项是什么? 注意样例中是三个参数 ...
- 巴什博奕小结 HDU2188 HDU1846 HDU2149
摘自百度百科: 巴什博奕(Bash Game):只有一堆n个物品,两个人轮流从这堆物品中取物,规定每次至少取一个,最多取m个.最后取光者得胜. 显然,如果n=m+1,那么由于一次最多只能取m个,所以, ...
- 如何获取AppStore软件安装包的路径
本帖最后由 chinald 于 2015-10-16 13:59 编辑 前言:本文介绍在Mac下如何找到AppStore下载的安装包路径,以及如何提取出来供以后使用,希望对大家有所帮助(前提:想要提取 ...
- XML Parser Errors See Details for more Information XML Parser Error on line 1: Document root ele
1.错误描写叙述 XML Parser Errors See Details for more Information XML Parser Error on line 1: Document roo ...
- 一位90后程序员的自述:如何从年薪3w到30w!
初入职场之时,大多数人都应该考虑过这样的一个问题,如何找到一种实用,简化web流程的方法,在工作之中能有所提升和突破. 学好哪些?基础必须精通! 九层之塔,起于垒土;千里之行,始于足下.入门之前,这些 ...
- CentOS下安装和配置MySQL-JDK-Tomcat-Nginx(个人官网环境搭建手册)
今天,重新弄我的个人云主机的环境,准备运营自己用Java写的个人官网等网站. 服务器环境:阿里云CentOS 6.4位 包括以下脚本在内的绝大部分命令和脚本,都是我亲自执行过,靠谱的. 完整的&quo ...
- MRTG Monitoring with ESXi Hosted Guest Return ‘interface is commented * has no ifSpeed property’
MRTG Monitoring with ESXi Hosted Guest Return ‘interface is commented * has no ifSpeed property’ Rec ...