传送门

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

首先行数一定是$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. codeforces 782B - The Meeting Place Cannot Be Changed

    time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standa ...

  2. compile time - run-time

    php.net Class member variables are called "properties". You may also see them referred to ...

  3. little_rockie

    https://www.cnblogs.com/nxld/p/6058591.html

  4. Rikka with Sequence---hdu5828(区间更新与查找 线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5828 给你n个数,m个操作,操作k,l,r, k=1时 区间[l,r]每个数加x: k=2时,区间[l ...

  5. grunt学习二

    1. 新建文件和文件目录 mkdir grunt-in-action cd grunt-in-action cd grunt-in-action mkdir grunt-empty cd grunt- ...

  6. mysql 数据操作 单表查询 目录

    mysql 数据操作 单表查询 mysql 数据操作 单表查询 简单查询 避免重复DISTINCT mysql 数据操作 单表查询 通过四则运算查询 mysql 数据操作 单表查询 concat()函 ...

  7. 怎样在 Ubuntu 上使用 ZFS 文件系统 | Linux 中国

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/F8qG7f9YD02Pe/article/details/79329762 http://mmbiz ...

  8. 【剑指offer】重建二叉树

    一.题目: 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7 ...

  9. C和C++不容易发现的区别

    1.char指针指向字符串常量 当下面的代码写到.c文件中时,可以正常运行;而写到.cpp文件中就会报错:无法从“const char [6]”转换为“char *”. char * c = &quo ...

  10. 关于Flag的定义

    最近在维护项目的代码,发现了由于Flag不一致导致的很多问题,现在对这一问题总结. 1,flag分为两种,可以组合的和不可以组合的.可以组合的flag适合用每一位表示一个含义.不适合组合的flag适合 ...