B. Remainders Game
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

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,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[剩余]的更多相关文章

  1. codeforces 687B - Remainders Game 数学相关(互质中国剩余定理)

    题意:给你x%ci=bi(x未知),是否能确定x%k的值(k已知) ——数学相关知识: 首先:我们知道一些事情,对于k,假设有ci%k==0,那么一定能确定x%k的值,比如k=5和ci=20,知道x% ...

  2. CodeForces 687B Remainders Game

    数论. 如果$x$不唯一,假设存在两个解,较大的为${x_1}$,较小的为${x_2}$. 那么, $\left\{ {\begin{array}{*{20}{c}}{{x_1}\% {c_i} = ...

  3. CodeForces 687B Remainders Game(数学,最小公倍数)

    题意:给定 n 个数,一个数 k,然后你知道一个数 x 取模这个 n 个的是几,最后问你取模 k,是几. 析:首先题意就看了好久,其实并不难,我们只要能从 n 个数的最小公倍数是 k的倍数即可,想想为 ...

  4. 【16.56%】【codeforces 687B】Remainders Game

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. Codeforces Round #360 (Div. 2) D. Remainders Game 中国剩余定理

    题目链接: 题目 D. Remainders Game time limit per test 1 second memory limit per test 256 megabytes 问题描述 To ...

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

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

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

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

  9. codeforces 688D D. Remainders Game(中国剩余定理)

    题目链接: D. Remainders Game time limit per test 1 second memory limit per test 256 megabytes input stan ...

随机推荐

  1. SAP ALV内嵌(In-place)Excel的问与答

    1.问题:点击ALV工具栏的"Excel"图标后,出现空白的内嵌Excel界面,无法正常显示报表数据.可按以下思路解决:(1)检查Excel中的宏安全设置选项.访问方法:启动Exc ...

  2. CoreDataManager-OC版-兼容iOS10以前的版本

    头文件: #import <Foundation/Foundation.h> #import <CoreData/CoreData.h> /** CoreData管理器 */ ...

  3. Android 视频播放器切换到下个视频时残留上个视频画面的解决办法

    最近在做一个Android视频播放器,遇到一个问题:切换到下一个视频时,中间会停留上一个视频的残存画面.   这是怎么回事?   我在网上找了很多资料,终于找到了原因:我是用自定义一个surfacev ...

  4. Ubuntu 安装系统资源托盘监视应用

    安装 sudo apt-get install indicator-multiload 打开 indicator-multiload 设置开机启动    sudo gedit /etc/rc.loca ...

  5. 【读书笔记】iOS-ARC-不要向已经释放的对象发送消息

    一,在AppDelegate.m中写入如下代码: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOpti ...

  6. Kotlin偏好设置

    Kotlin的强悍震精了我,android中每个应用都会用到SharedPreference在Kotlin中使用竟是如此简单! package com.android.extkt import and ...

  7. KVC与KVO的实现原理

    |KVC的用法 1.KVC既键值编码(Key Value Coding),基于NSKeyValueCoding协议,它是以字符串的形式来操作对象的成员变量,也就是通过字符串key来指定要操作的成员变量 ...

  8. Adobe Flash player 10 提示:Error#2044:未处理的IOErrorEvent. text=Error#2036:加载未完成 的解决方法

    在“我的电脑”上单击鼠标右键,选择管理,在管理窗口的左栏中打开“服务和应用程序”,点击“服务”,在右边窗口中双击打开名称为“Smart Card”的服务,“常规”->“启动类型”选为自动,“登录 ...

  9. 8、需求分析师要阅读的书籍 - IT软件人员书籍系列文章

    需求分析是软件项目开始阶段重要的一步.而需求分析是项目经理或产品经理需要经历的一环,所以说需求分析是项目经理或产品经理需要具备的知识.但是,项目角色中却分离出了需求分析师这个角色,也就是说,在大型的或 ...

  10. Apache安装

    记录安装Apache的流程,没有进行详细配置,只是记录搭建服务器的流程用于学习Ajax等知识,方便以后重新安装,不用每次都翻别人博客学习安装了,大神看到这里可以关掉这个粗糙简陋的博文了. 1. 官网上 ...