题意:已知n个数,第i个为ci,给定一个数x mod ci的结果,再给点一个k,问能不能知道x mod k的值?

分析:刚看题目的我一脸蒙蔽,对题意有点不理解,能的情况似乎有很多,我该从哪里下手呢?

先从不能的情况来看,可以知道,如果不能知道x mod k的值,当且仅当有两个解x1,x2, x1 ≡ x2(mod ci)x1 ≢ x2 (mod k) 左边这个是不同余的意思,

为什么是这样的呢?因为题目中说x mod k的值是唯一的,我们却会出现两个满足题意的x值 mod k的值不同,这就矛盾了。

那么我们怎样求解这两个同余式呢?如果x1 ≡ x2(mod ci),那么(x1 - x2) % ci = 0,所以x1 - x2一定是ci的最小公倍数的倍数,

然后对第二个式子变形一下:(x1 - x2) % k != 0,也就是说k不整除lcm{ci}那么这道题就变成了要我们求解lcm{ci}到底是不是k的倍数。

但是直接求会lcm会爆掉啊,如果取模的话涉及到除法要求逆元复杂度又会爆炸,该怎么处理?

正确的方法是分解质因数:将k表示为p1^k1 * p2 ^ k2 * ... *pn ^ kn的形式,如果lcm{ci}是k的倍数,那么p1^k1、p2^k2...pn^kn一定会全部

出现在某些ci中,我们只需要在读入的时候检验一下打个标记就好了。一位大神说的对:lcm就是质因子的并集,gcd就是质因子的交集,

遇到gcd、lcm,分解一下质因子不失为一种好的方法。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath> using namespace std; int n, k, c,tot,prime[];
bool vis[]; int main()
{
scanf("%d%d", &n, &k);
for (int i = ; i <= sqrt(k); i++)
{
if (k % i == )
{
int t = ;
while (k % i == )
{
t *= i;
k /= i;
}
prime[++tot] = t;
}
}
if (k)
prime[++tot] = k;
for (int i = ; i <= n; i++)
{
int c;
scanf("%d", &c);
for (int j = ; j <= tot; j++)
if (c % prime[j] == )
vis[j] = ;
}
for (int i = ; i <= tot; i++)
if (!vis[i])
{
printf("No\n");
return ;
}
printf("Yes\n"); return ;
}

CF687B Remainders Game的更多相关文章

  1. oi初级数学知识

    一.先是一些整除的性质: •整除:若a=bk,其中a,b,k都是整数,则b整除a,记做b|a. •也称b是a的约数(因数),a是b的倍数 •显而易见的性质: •1整除任何数,任何数都整除0 •若a|b ...

  2. Codeforces 687B. Remainders Game[剩余]

    B. Remainders Game time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  3. codeforces 360 D - Remainders Game

    D - Remainders Game Description Today Pari and Arya are playing a game called Remainders. Pari choos ...

  4. codeforces 616E Sum of Remainders (数论,找规律)

    E. Sum of Remainders time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

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

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

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

  7. Codeforces 616E - Sum of Remainders

    616E Sum of Remainders Calculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + - + n mod m. As ...

  8. Codeforces 999D Equalize the Remainders (set使用)

    题目连接:Equalize the Remainders 题意:n个数字,对m取余有m种情况,使得每种情况的个数都为n/m个(保证n%m=0),最少需要操作多少次? 每次操作可以把某个数字+1.输出最 ...

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

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

随机推荐

  1. [转载]浅析为什么char类型的范围是 —128~+127

    http://blog.csdn.net/daiyutage/article/details/8575248 在C语言中, signed char 类型的范围为-128~127,每本教科书上也这么写, ...

  2. div+css+jQuery简单实现投票功能

    昨天看到C#群里有人问一个投票功能如何实现... 我对此很感兴趣,为了练习一下,就有了以下代码. 投票功能使用jQuery实现..纯html代码...数据通过json字符串传递,通过 eval转换为j ...

  3. 【leetcode 简单】 第八十四题 两个数组的交集

    给定两个数组,编写一个函数来计算它们的交集. 示例 1: 输入: nums1 = [1,2,2,1], nums2 = [2,2] 输出: [2] 示例 2: 输入: nums1 = [4,9,5], ...

  4. python初步学习-python模块之 commands

    commands 通过 os.popen() 执行 shell 命令,返回两个对象,一个是 状态码(Int).另一个为命令输出(str) commands.getoutput(cmd) 返回命令执行输 ...

  5. 30、hashCode方法

    HashCode方法的作用 在HashSet中的元素是不能重复的,jvm可以通过equals方法来判断两个对象是否相同,假设自定义一个Person类里面有10个成员变量,每调用一次equals方法需要 ...

  6. [转]C++ 取代switch的三种方法

    1.常规switch enum EnumType { enumOne, enumTwo, enumThree }; void showMessage(int type) { switch(type) ...

  7. meterpreter使用

    1.基本命令 background:将meterpreter终端隐藏在后台 sessions:查看已经成功获取的会话,想继续与某会话进行交互使用sessions –i quit:直接关闭当前meter ...

  8. 采用dlopen、dlsym、dlclose加载动态链接库【总结】【转】

    转自:https://www.cnblogs.com/Anker/p/3746802.html 1.前言 为了使程序方便扩展,具备通用性,可以采用插件形式.采用异步事件驱动模型,保证主程序逻辑不变,将 ...

  9. ASP.net-空白页的问题

    protected void Application_Error(object sender, EventArgs e)         {             ILog log = LogMan ...

  10. 【小程序开发】上拉加载更多demo

    wxml: <scroll-view class='swiper-scroll' scroll-y="{{true}}" bindscrolltolower="lo ...