题目链接:

题目

D. Remainders Game

time limit per test 1 second

memory limit per test 256 megabytes

问题描述

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.

样例

input

4 5

2 3 5 12

output

Yes

input

2 7

2 3

output

No

题意

给你n个数和一个k,求x%k的值,没有告诉你x是多少,只告诉你能够计算x%ci的值。问能不能根据这n次测试唯一确定x%k。

题解

思路1:

结论:无法唯一确定x%k <==> k不能整除lcm(c1,...,cn);

充分性:

无法唯一确定x%k --> 存在两个数x1,x2对于任意的ci取余的值都相等,对k取值的值却不等。

  • x1,x2对任意的ci取余都相等 --> ci|(x1-x2) --> lcm(ci)|(x1-x2).
  • x1,x2对k取余的值不等 --> k不整除(x1-x2) --> k不整除lcm(ci)

必要性:

我们令x1=2*lcm(ci),x2=lcm(ci),则易知有x1,x2对于任意的ci取余的值都相等,且因为k不能整除lcm(ci),所以x1,x2对k取余的值不等。 所以ci不能确定x%k的值。

思路2:

题目已经给我们n个线性同余方程:x%c[i]==a[i]%c[i]。

由于a数组是由我们任意选择的,所以我们可以构造所有的a相等,从而使得对于任意的i,j,有a[i]%(gcd(ci,cj))等于a[j]%(gcd(ci,cj))。这样,由中国剩余定理就可以知道x%(lcm(c1,...,cn))有唯一解了。 那么我们只要使得k能整除lcm(c1,...,cn)那么易知x%k的值也是固定的。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std; typedef __int64 LL; LL n, k; LL gcd(LL a, LL b) { return b == 0 ? a : gcd(b, a%b); }
LL lcm(LL a, LL b) { return a*b / gcd(a, b); } int main() {
scanf("%I64d%I64d", &n, &k);
LL lcm_ci = 1;
bool su = 0;
for (int i = 1; i <= n; i++) {
LL x;
scanf("%I64d", &x);
lcm_ci = lcm(lcm_ci, x);
lcm_ci = gcd(k, lcm_ci);
if (lcm_ci == k) {
su = 1; break;
}
}
if (su) puts("Yes");
else puts("No");
return 0;
}

Codeforces Round #360 (Div. 2) D. Remainders Game 中国剩余定理的更多相关文章

  1. 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 ...

  2. Codeforces Round #360 (Div. 2) D. Remainders Game 数学

    D. Remainders Game 题目连接: http://www.codeforces.com/contest/688/problem/D Description Today Pari and ...

  3. 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 ...

  4. Codeforces Round #360 (Div. 2) C. NP-Hard Problem 水题

    C. NP-Hard Problem 题目连接: http://www.codeforces.com/contest/688/problem/C Description Recently, Pari ...

  5. Codeforces Round #360 (Div. 2) B. Lovely Palindromes 水题

    B. Lovely Palindromes 题目连接: http://www.codeforces.com/contest/688/problem/B Description Pari has a f ...

  6. Codeforces Round #360 (Div. 2) A. Opponents 水题

    A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...

  7. Codeforces Round #360 (Div. 1)A (二分图&dfs染色)

    题目链接:http://codeforces.com/problemset/problem/687/A 题意:给出一个n个点m条边的图,分别将每条边连接的两个点放到两个集合中,输出两个集合中的点,若不 ...

  8. 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 ...

  9. 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, ...

随机推荐

  1. RedHat Install

    1. 插入光盘1并从光盘启动加载镜像文件 2. 回车后进入安装流程 3. 选择语言 4. 选择键盘布局 5. 鼠标配置 6. 选择安装类型 7. 选择分区类型 8. 添加一个boot分区 9. 新建一 ...

  2. iOS 高阶

    1.UIStoryBoard 2. segue跳转传值 3. UIColor配色 //1. 十进制配色 [UIColor colorWithRed:163.0/255.0 green:148.0/25 ...

  3. 一个基于MBProgressHUD的自定义视图hud例子

    项目中用到的一个hud,基于MBProgressHUD,使用自定义视图实现的,动画效果是从网上参考的,并不是很理想.有需要的可以看看,这里是源码(源码用了cocoapods,运行前需要pod inst ...

  4. 兼容IE,chrome 等所有浏览器 回到顶部代码

    今天在博客园看到一片帖子回到顶部代码,索性就看了下,但是发现在非IE浏览器下可以运行,在IE浏览器下却运行不了. 故将其代码搬弄过来做了些许修改后,完美支持了IE下的运行. 主要实现功能代码文件: & ...

  5. JS学习第四课

    当我们删除某列表格,再添加新的一列时,它的序号该如何控制呢.这里id=oTab.tBodies[0].rows.length+1        otd.innerHTML=id++;   很关键哦. ...

  6. 济南学习 Day1 T1 am

    题意:给你两个日期,问这两个日期差了多少毫秒 #include<cstdio> #include<cstring> #include<ctime> #include ...

  7. 洛谷 P2670 扫雷游戏==Codevs 5129 扫雷游戏

    题目描述 扫雷游戏是一款十分经典的单机小游戏.在n行m列的雷区中有一些格子含有地雷(称之为地雷格),其他格子不含地雷(称之为非地雷格).玩家翻开一个非地雷格时,该格将会出现一个数字——提示周围格子中有 ...

  8. 8.samba server与client配置

    server端 1.安装samba:yum install -y samba\* 增加samba用户: useradd smb用户名               smbpasswd -a smb用户名 ...

  9. Linux 如何设置只允许域名访问站点而禁止IP访问站点

    最近在论坛里看到有人问到 Linux 如何设置只允许域名访问站点而禁止IP访问站点的问题,之前自己也用过这个功能,可以防止别人用 IP 地址来访问到自己的网站,下面我就我自己的环境给出解决方法,我用的 ...

  10. php var_export与var_dump 输出的不同

    var_export必须返回合法的php代码,var_export返回的代码,可以直接当作php代码赋值个一个变量. 而这个变量就会取得和被var_export一样的类型的值.   问题描述: 在跟踪 ...