CF#338D. GCD Table
简单的中国剩余定理练习。
首先行数一定是$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 <iostream>
#include <queue>
#include <map>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <ctime>
#include <bitset>
#include <set>
#include <vector>
#include <complex>
using namespace std;
#define ll long long
#define up(i,j,n) for(ll i=j;i<=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<<50;
inline ll read(){
char ch=getchar();ll x=0,f=1;
while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='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<0) 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的更多相关文章
- Codeforces 338D GCD Table 中国剩余定理
主题链接:点击打开链接 特定n*m矩阵,[i,j]分值为gcd(i,j) 给定一个k长的序列,问能否匹配上 矩阵的某一行的连续k个元素 思路: 我们要求出一个解(i,j) 使得 i<=n &am ...
- codeforces 338D GCD Table
什么都不会只能学数论QAQ 英文原题不贴了 题意: 有一张N*M的表格,i行j列的元素是gcd(i,j)读入一个长度为k,元素大小不超过10^12的序列a[1..k],问这个序列是否在表格的某一行中出 ...
- 【CF#338D】GCD Table
[题目描述] 有一张N,M<=10^12的表格,i行j列的元素是gcd(i,j) 读入一个长度不超过10^4,元素不超过10^12的序列a[1..k],问是否在某一行中出现过 [题解] 要保证g ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- CF582A GCD Table
A. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
随机推荐
- Spark+IDEA单机版环境搭建+IDEA快捷键
1. IDEA中配置Spark运行环境 请参考博文:http://www.cnblogs.com/jackchen-Net/p/6867838.html 3.1.Project Struct查看项目的 ...
- thinkphp 如何查询数据库
在控制器中使用M(); 数据表: 一.查询方式 1.字符串作为条件 2.使用索引数组作为条件查询条件 //可以更改逻辑关系 $condition['_logic'] = 'OR'; 二.表达式查询 三 ...
- 【Jmeter】如何通过文件导入方式对用户名和密码进行参数化设置
JMeter 参数化 注意:param和data body只能用一个.所有任何一个里面有内容,切换都会报错,这不是问题,jmeter是这么设计的 方法一:通过添加CSV Data Set Config ...
- dedecms网站迁移时记得将安装目录放空 附迁移的正确方法
这段时间在赶一些新项目,我们建站一般都在本地服务器搭建起来,测试得差不多了才传到网上,这样对蜘蛛也相对友好一些,要不然改来改去变化太大给搜索引擎的第一印象很不好.但是由于本地环境和服务器环境还是有一些 ...
- ul li剧中对齐
html: <div class="footernav"> <ul> <li>首页</li> <li>文章</li ...
- vue学习六之vuex
由于状态零散地分布在许多组件和组件之间的交互中,大型应用复杂度也经常逐渐增长.为了解决这个问题,Vue 提供 vuex. 什么是Vuex Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式 ...
- 谷歌浏览器:audio如何隐藏下载按钮
当我们使用原生的audio标签时,可以看到如下的效果. 那么如何让下载按钮隐藏掉呢? 1. controlsList="nodownload" // 这个方法只支持 Chrome ...
- OpenCV中PCA实现人脸降维
前言: PCA是大家经常用来减少数据集的维数,同时保留数据集中对方差贡献最大的特征来达到简化数据集的目的.本文通过使用PCA来提取人脸中的特征脸这个例子,来熟悉下在oepncv中怎样使用PCA这个类. ...
- soapUI-JDBC Request
1.1.1 JDBC Requet 1.1.1.1 概述 – JDBC Request Option Description JDBC Request TestStep Toolbar 对JDB ...
- 实体框架 Code First
原文:https://msdn.microsoft.com/zh-cn/en-zn/data/jj591621