传送门

简单的中国剩余定理练习。

首先行数一定是$lcm$,然后只要确定最小的列数就能判定解合不合法了。

我们可以得到线性模方程组:

$y \equiv 0 \pmod{a_1}$

$y+1 \equiv 0 \pmod {a_2}$

$y+2 \equiv 0 \pmod {a_3}$

$...$

$y+n \equiv 0 \pmod {a_{n+1}}$

然后CRT搞出来一组解,暴力判判就OK了。

//CF338D
//by Cydiater
//2017.2.20
#include &ltiostream>
#include &ltqueue>
#include &ltmap>
#include &ltcstring>
#include &ltstring>
#include &ltalgorithm>
#include &ltcmath>
#include &ltcstdlib>
#include &ltcstdio>
#include &ltiomanip>
#include &ltctime>
#include &ltbitset>
#include &ltset>
#include &ltvector>
#include &ltcomplex>
using namespace std;
#define ll long long
#define up(i,j,n)	for(ll i=j;i&lt=n;i++)
#define down(i,j,n)	for(ll i=j;i>=n;i--)
#define cmax(a,b)	a=max(a,b)
#define cmin(a,b)	a=min(a,b)
const ll MAXN=1e5+5;
const ll oo=1LL&lt<50;
inline ll read(){
	char ch=getchar();ll x=0,f=1;
	while(ch>'9'||ch&lt'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch&lt='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
ll N,M,K,m[MAXN],lcm=1,a[MAXN],a1,m1;
namespace solution{
	ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
	void exgcd(ll a,ll b,ll &x,ll &y){
		if(!b){x=1;y=0;return;}
		exgcd(b,a%b,y,x);
		y-=a/b*x;
	}
	void CRT(){
		a1=a[1];m1=m[1];
		up(i,2,K){
			ll a2=a[i],m2=m[i],x,y,d=gcd(m1,m2);
			if((a2-a1)%d){a1=oo;return;}
			exgcd(m1,m2,x,y);
			ll mod=m2/d;
			x=((x*((a2-a1)/d)%mod+mod)%mod+mod)%mod;
			a1+=x*m1;
			m1=m1*m2/d;
			a1=(a1+m1)%m1;
		}
	}
	void Prepare(){
		N=read();M=read();K=read();
		up(i,1,K){
			m[i]=read();a[i]=1-i;
			lcm=lcm/gcd(lcm,m[i])*m[i];
		}
	}
	void Solve(){
		if(lcm>N)puts("NO");
		else{
			CRT();
			if(a1+K-1>M||a1&lt0)	puts("NO");
			else{
				if(a1==0)a1=lcm;
				if(a1+K-1>M){
					puts("NO");
					return;
				}
				up(i,1,K)if(gcd(lcm,a1+i-1)!=m[i]){
					puts("NO");
					return;
				}
				puts("YES");
			}
		}
	}
}
int main(){
	//freopen("input.in","r",stdin);
	using namespace solution;
	Prepare();
	Solve();
	return 0;
}

CF#338D. GCD Table的更多相关文章

  1. Codeforces 338D GCD Table 中国剩余定理

    主题链接:点击打开链接 特定n*m矩阵,[i,j]分值为gcd(i,j) 给定一个k长的序列,问能否匹配上 矩阵的某一行的连续k个元素 思路: 我们要求出一个解(i,j) 使得 i<=n &am ...

  2. codeforces 338D GCD Table

    什么都不会只能学数论QAQ 英文原题不贴了 题意: 有一张N*M的表格,i行j列的元素是gcd(i,j)读入一个长度为k,元素大小不超过10^12的序列a[1..k],问这个序列是否在表格的某一行中出 ...

  3. 【CF#338D】GCD Table

    [题目描述] 有一张N,M<=10^12的表格,i行j列的元素是gcd(i,j) 读入一个长度不超过10^4,元素不超过10^12的序列a[1..k],问是否在某一行中出现过 [题解] 要保证g ...

  4. Codeforces Round #323 (Div. 2) C.GCD Table

    C. GCD Table The GCD table G of size n × n for an array of positive integers a of length n is define ...

  5. Codeforces Round #323 (Div. 1) A. GCD Table

    A. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  6. Codeforces Round #323 (Div. 2) C. GCD Table 暴力

    C. GCD Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/583/problem/C ...

  7. SPOJ PGCD 4491. Primes in GCD Table && BZOJ 2820 YY的GCD (莫比乌斯反演)

    4491. Primes in GCD Table Problem code: PGCD Johnny has created a table which encodes the results of ...

  8. Codeforces Round #323 (Div. 2) C. GCD Table map

    题目链接:http://codeforces.com/contest/583/problem/C C. GCD Table time limit per test 2 seconds memory l ...

  9. CF582A GCD Table

    A. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

随机推荐

  1. 机器学习TensorFlow安装经过摘要

    第一步:我在Github上面下载了TensorFlow项目源码 第二步:在tensorflow-master/tensorflow/docs_src/install里面找到了install_mac.m ...

  2. 启动了SSH服务后,一定要关闭Telnet服务

    https://baike.baidu.com/item/ssh/10407 https://baike.baidu.com/item/Telnet/810597

  3. iOS-多语言版本的开发(一)(转载)

    引言  多语言 & 本地化,随你怎么叫,道理差不多:一个App 要想走出国门,只支持一种语言是不能够的,也是不可能的,多元化世界已经融入我们的生活,对于一些应用,开发多语言版本,已经是不可避免 ...

  4. linux elasticsearch-5.1.1的安装

    (一)下载elasticsearch linux安装包 https://www.elastic.co/downloads/past-releases,然后解压,然后要有对应的java8,即必须先安装j ...

  5. Chrome百度不显示中文字体

    chrome://flags/ 启用DirectWrite 关闭就可以了

  6. LeetCode 第 342 题(Power of Four)

    LeetCode 第 342 题(Power of Four) Given an integer (signed 32 bits), write a function to check whether ...

  7. ie兼容图片缩小后模糊失真(锯齿)问题

    解决IE下图片缩小失真(有锯齿)的问题   首先,这不是一个新鲜玩意儿,很多大牛08年就发现了. 其次,这是个所有IE下普遍都会遇到的问题,而非只针对于IE67.(百度了一下,大半左右的文章是针对于I ...

  8. xss跨站脚本攻击及xss漏洞防范

    xss跨站脚本攻击(Cross Site Scripting,因与css样式表相似故缩写为XSS).恶意攻击者往Web页面里插入恶意Script代码,当用户浏览该页之时,嵌入其中Web里面的Scrip ...

  9. 如何在 vue 项目里正确地引用 jquery 和 jquery-ui的插件

    copy内容的网址: https://segmentfault.com/a/1190000007020623 使用vue-cli构建的vue项目,webpack的配置文件是分散在很多地方的,而我们需要 ...

  10. 总结)Nginx/LVS/HAProxy负载均衡软件的优缺点详解

    总结)Nginx/LVS/HAProxy负载均衡软件的优缺点详解 PS:Nginx/LVS/HAProxy是目前使用最广泛的三种负载均衡软件,本人都在多个项目中实施过,参考了一些资料,结合自己的一些使 ...