codeforces 687B - Remainders Game 数学相关(互质中国剩余定理)
题意:给你x%ci=bi(x未知),是否能确定x%k的值(k已知)
——数学相关知识:
首先:我们知道一些事情,对于k,假设有ci%k==0,那么一定能确定x%k的值,比如k=5和ci=20,知道x%20=y,那么ans=x%k=y%5;
介绍(互质版)中国剩余定理,假设已知m1,m2,mn,两两互质,且又知道x%m1,x%m2..x%mn分别等于多少
设M=m1*m2*m3..mn,那么x在模M的剩余系下只有唯一解(也就是知道了上面的模线性方程组,就可以求出x%M等于多少)
——此题解法
针对这个题呢,我们要确定x%k,只要保证知道上述的互质的模线性方程组就好
怎么样得到模线性方程组呢,直接把k唯一分解就好
即:k=p1^k1*p2^k2...*pr^kn,如果任意i,都有pi^ki的倍数出现在集合中(这一点如果不懂可以看上面,如果知道一个数倍数的取模,那么它肯定也知道),那么k就能被猜出来。
分析:只要保证k能整除ci的最小公倍数即可,由于太大,所以通过暴力分解因子的办法来判断
#include <cstdio>
#include <iostream>
#include <ctime>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const int N=1e5+;
const int INF=0x3f3f3f3f;
const int mod=1e9+;
bool cov[];
int n,k,cnt,fac[];
int main(){
scanf("%d%d",&n,&k);
for(int i=;i<=k;++i){
if(k%i)continue;
int cur=;
while(k%i==)cur*=i,k/=i;
fac[++cnt]=cur;
}
for(int i=;i<n;++i){
int x;scanf("%d",&x);
for(int j=;j<=cnt;++j)
if(x%fac[j]==)cov[j]=true;
}
bool flag=;
for(int i=;i<=cnt;++i)
if(!cov[i])flag=;
if(flag)printf("Yes\n");
else printf("No\n");
return ;
}
codeforces 687B - Remainders Game 数学相关(互质中国剩余定理)的更多相关文章
- Educational Codeforces Round 16 D. Two Arithmetic Progressions (不互质中国剩余定理)
Two Arithmetic Progressions 题目链接: http://codeforces.com/contest/710/problem/D Description You are gi ...
- CodeForces 687B Remainders Game(数学,最小公倍数)
题意:给定 n 个数,一个数 k,然后你知道一个数 x 取模这个 n 个的是几,最后问你取模 k,是几. 析:首先题意就看了好久,其实并不难,我们只要能从 n 个数的最小公倍数是 k的倍数即可,想想为 ...
- Codeforces 687B. Remainders Game[剩余]
B. Remainders Game time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- CodeForces 687B Remainders Game
数论. 如果$x$不唯一,假设存在两个解,较大的为${x_1}$,较小的为${x_2}$. 那么, $\left\{ {\begin{array}{*{20}{c}}{{x_1}\% {c_i} = ...
- Codeforces Round #360 (Div. 2) D. Remainders Game 数学
D. Remainders Game 题目连接: http://www.codeforces.com/contest/688/problem/D Description Today Pari and ...
- 【16.56%】【codeforces 687B】Remainders Game
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces 959 树构造 暴力求最小字典序互质序列
A B C 题目给你一个结论 最少需要min((odd,even)个结点可以把一棵树的全部边连起来 要求你输出两颗树 一棵树结论是正确的 另外一棵结论是正确的 正确结论的树很好造 主要是错误的树 题目 ...
- 数学--数论--HDU1825(积性函数性质+和函数公式+快速模幂+非互质求逆元)
As we all know, the next Olympic Games will be held in Beijing in 2008. So the year 2008 seems a lit ...
- [总结]数论和组合计数类数学相关(定理&证明&板子)
0 写在前面 0.0 前言 由于我太菜了,导致一些东西一学就忘,特开此文来记录下最让我头痛的数学相关问题. 一些引用的文字都注释了原文链接,若侵犯了您的权益,敬请告知:若文章中出现错误,也烦请告知. ...
随机推荐
- struts2 json关于Date日期的解析
在get方法前加上: @JSON(format="yyyy-MM-dd HH:mm:ss")
- XCODE 出现 The operation couldn't be completed.(LaunchServicesError error 0.)错误修复
XCODE 出现 The operation couldn't be completed.(LaunchServicesError error 0.)错误修复 XCODE 出现 The opera ...
- 服务器端json解析
1.客户端通过http传上来的可定都是json数据啊,json数据传到服务器端,就要通过键值对getkey方法得到具体值,对吧,然后再操控具体值. 2.JSONObject与JSONArray: Js ...
- 企业用户2T(含秒传),普通用户20G
周鸿祎一定要看的建议(要求置顶):可以解决本次云盘事件的建议!!! 2016-10-23 20:23 | 复制链接 | 淘帖 461334 本帖最后由 cqthxin 于 2016-10-23 20: ...
- Arc Engiene读取文档的属性
设计界面 创建类 代码如下 using System; using System.Collections.Generic; using System.Linq; using System.Text; ...
- Spring中的mappingResources和mappingDirectoryLocations
今天使用Spring+Hibernate进行事务管理,按照顺序也就是配置,DataSource,Sessionfactory,事务管理器以及拦截器. DateSource可以直接使用Hibernate ...
- ios摇一摇
-(void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { if (motion==UIEventSubtypeMo ...
- android移植
root@phone-desktop:/opt/4418-source/android4.4.2_r1# ./device/nexell/tools/build.sh -b drone2 -t u-b ...
- struts1,struts2,springMVC终极对比
最近做项目用到了struts2,之前一直是用struts1和springMVC.感觉到了struts2从很大程度上和这两个还是有很大区别的,所以今天搜集了些资料,给他们做一下对比. Struts1官方 ...
- [LeetCode#249] Group Shifted Strings
Problem: Given a string, we can "shift" each of its letter to its successive letter, for e ...