题意:已知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. Is it possible to create @Around Aspect for feign.Client

    https://github.com/spring-cloud/spring-cloud-openfeign/issues/59 看到github 有人问这个问题,做了个示例: import org. ...

  2. HDU 1846 Brave Game 巴什博奕

    解题报告:Alice和Bob在做一个取石子游戏,有一堆n个石子,然后规定每个人每次最少要去1个石子,最多可以取m个石子,最后一次取完石子的人为胜. 巴什博奕,关键是找到必胜点和必败点,我们可以先列举出 ...

  3. 【译】第四篇 Integration Services:增量加载-Updating Rows

    本篇文章是Integration Services系列的第四篇,详细内容请参考原文. 回顾增量加载记住,在SSIS增量加载有三个使用案例:1.New rows-add rows to the dest ...

  4. JavaScript 优雅的实现方式包含你可能不知道的知识点

    有些东西很好用,但是你未必知道:有些东西你可能用过,但是你未必知道原理. 实现一个目的有多种途径,俗话说,条条大路通罗马.很多内容来自平时的一些收集以及过往博客文章底下的精彩评论,收集整理拓展一波,发 ...

  5. 20155303 《Java程序设计》实验一(Java开发环境的熟悉)实验报告

    20155303 <Java程序设计>实验一(Java开发环境的熟悉)实验报告 一.实验内容及步骤 (一)使用JDK编译.运行简单的java程序 命令行下的程序开发 步骤一(新建文件夹): ...

  6. C++面试常见问题

    转载:https://zhuanlan.zhihu.com/p/34016871?utm_source=qq&utm_medium=social 1.在C++ 程序中调用被C 编译器编译后的函 ...

  7. HDU 2825 Wireless Password

    题目链接:HDU-2825 题意:给出m个单词,要构造出满足包含其中大于等于k个单词的字符串,字符只包括小写字母,问长度为n的这样的串有多少个. 思路:令dp[i][j][k]表示当前已经构造了i个字 ...

  8. Nagios Openstack Plugin

    Some simple example for checking Openstack services check nova service list #!/bin/sh export OS_PROJ ...

  9. docker修改docker0 mtu

    由于docker宿主机设置了mtu造成docker镜像中mtu和宿主机mtu不匹配,大包后网络不同.所以需要设置docker0的mtu. 1.修改docker.service vi /usr/lib/ ...

  10. 通过field:global给子元素添加css样式

    {dede:arclist row=5 typeid=200} <li [field:global runphp=’yes’ name=autoindex](@me==1)?@me=”class ...