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 ...
随机推荐
- 2018-2019-2 20165330《网络对抗技术》Exp3 免杀原理与实践
目录 基础问题 相关知识 实验内容 实验步骤 实验过程中遇到的问题 离实战还缺些什么技术或步骤? 实验总结与体会 实验内容 正确使用msf编码器,msfvenom生成如jar之类的其他文件,veil- ...
- centos 7 yum configuration; yum localinstall
Linux下对于软件包的管理使用rpm管理方式.直接使用rpm包管理工具来进行rpm包的安装,升级,卸载时,对于最让人头疼的莫过与包之间的依赖关系.yum作为一个rpm包前端管理工具,可以自动处理依赖 ...
- django比较相等或者不相等的模板语法ifequal / ifnotequal
转自:http://blog.csdn.net/goupper1991/article/details/50768346 ifequal / ifnotequal 在模板语言里比较两个值并且 ...
- 网页设计师必知的10则SEO
如今,Web设计师在设计Web外观与风格的同时,往往还负责了前端代码的编写.换???话说,SEO的相当一部分责任是落在他们肩上的.然而,大 量的 Web设计师对SEO的熟悉程度仍不足以让他们写出一个符 ...
- 2018/03/21 每日一个Linux命令 之 scp
在平常的工作和学习中,难免要和远程服务器产生一些文件的交互. 当然也有 xftp 这种工具在,干的事情是一样的,不过今天还是介绍命令行下 scp 的用法,毕竟每天都在和命令行打交道. -- scp 命 ...
- mongodb基础语法
Mongodb与关系型数据库最大的区别就是无约束, 既无字段(外键等)约束, 也没有数据类型约束, 以json存储 安装 启动Mongodb(默认在c盘找 data/db/文件夹) 服务端: mong ...
- AspNetPager使用方法
一.AspNetPager支持两种方式分页: 一种是PostBack方式分页, 一种是通过Url来实现分页以及Url重写功能 二.AspNetPager支持各种数据绑定控件GridView.DataG ...
- mysql 约束条件目录
mysql 约束条件 mysql 约束条件 not null与default mysql 约束条件 unique key 唯一的键 mysql primary key 主键 mysql auto_in ...
- 优化dedecms设置文章url自定义规则
DEDECMS自定义URL规则的做得还是不错的,可清楚的看到URL中可用到的变量,并且这些变量包括年月日.时间戳.文章 ID.拼音+文章ID.拼音部首.栏目目录及日期加ID转换的字符串等,基本可以很好 ...
- 编译错误 ----- /usr/bin/ld: cannot find -lc
yum install glibc-static glib-static是Gcc链接时使用到的库.