codeforces 338D GCD Table
什么都不会只能学数论QAQ
英文原题不贴了
题意:
有一张N*M的表格,i行j列的元素是gcd(i,j)
读入一个长度为k,元素大小不超过10^12的序列a[1..k],问这个序列是否在表格的某一行中出现过
1<=N,M<=10^12
1<=k<=10^4
恩
首先显然x=lcm(a[i])
然后(y+i-1)%a[i]==0
即y%[i]=1-n
然后就神奇地变成了中国剩余定理
求出x和y后判无解即可,情况比较多
首先如果x和y超过n,m的范围或<0显然不对
然后注意枚举i看gcd(x,y+i-1)是否等于a[i]
恩?好像也不多
注意因为这个表示直接定义好的并没有实质地给出来,所以n,m都可以把int爆了
所有的计算过程都需要longlong?
什么都不会只能学数论QAQ
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define ll long long
ll rd(){ll z=,mk=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-')mk=-; ch=getchar();}
while(ch>=''&&ch<=''){z=(z<<)+(z<<)+ch-''; ch=getchar();}
return z*mk;
}
ll n,m,o; ll mo[],a[];
ll exgcd(ll a,ll b,ll &x,ll &y){
if(!b){ x=,y=; return a;}
ll d=exgcd(b,a%b,x,y);
ll tmp=x; x=y,y=tmp-a/b*y;
return d;
}
ll chn(){
ll M=mo[],A=a[],k,y;
for(int i=;i<=o;++i){
ll tmp=a[i]-A,d=exgcd(M,mo[i],k,y);
if(tmp%d) return -;
ll tm=mo[i]/d;
k=(k*tmp/d%tm+tm)%tm,A+=k*M,M=M*mo[i]/d,A=(A+M)%M;
}
return A;
}
int main(){freopen("ddd.in","r",stdin);
cin>>n>>m>>o;
for(int i=;i<=o;++i) mo[i]=rd(),a[i]=-i;
int y=chn();
ll x=,d;
for(int i=;i<=o;++i){
d=exgcd(x,mo[i],d,d);
x=x*mo[i]/d;
}
if(!y) y=x;
if(y< || y+o->m || x>n){ cout<<"NO"<<endl; return ;}
for(int i=;i<=o;++i)if(exgcd(x,y+i-,d,d)!=mo[i]){ cout<<"NO"<<endl; return ;}
cout<<"YES"<<endl;
return ;
}
codeforces 338D GCD Table的更多相关文章
- Codeforces 338D GCD Table 中国剩余定理
主题链接:点击打开链接 特定n*m矩阵,[i,j]分值为gcd(i,j) 给定一个k长的序列,问能否匹配上 矩阵的某一行的连续k个元素 思路: 我们要求出一个解(i,j) 使得 i<=n &am ...
- codeforces 582A. GCD Table 解题报告
题目链接:http://codeforces.com/problemset/problem/582/A 网上很多题解,就不说了,直接贴代码= = 官方题解: http://codeforces.com ...
- CodeForces - 583C GCD Table map的auto遍历 ,有点贪心的想法
题意:给你n*n gcd表中的所有数(以任意顺序) ,求对角线上的n个数分别是什么.gcd表定义如下,先将n个数填在对角线的上,然后将各个格子填上对应对角线上的数的gcd值,也就是V[i][j]=gc ...
- CF#338D. GCD Table
传送门 简单的中国剩余定理练习. 首先行数一定是$lcm$,然后只要确定最小的列数就能判定解合不合法了. 我们可以得到线性模方程组: $y \equiv 0 \pmod{a_1}$ $y+1 \equ ...
- codeforces 582A GCD Table
题意简述: 给定一个长度为$n$的序列 将这个序列里的数两两求$gcd$得到$n^2$个数 将这$n^2$个数打乱顺序给出 求原序列的一种可能的情况 ------------------------- ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- jquery 获取当前点击的是谁
//今天早上有人问这个问题 想着没写过jquery的笔记 //那就随便写一下吧 下面两个方法 根据不同情况而定用哪种方法$(".class").click(function(){ ...
- gym 101081 gym F. Auction of Services 最小生成树+倍增LCA
F. Auction of Services time limit per test 2.0 s memory limit per test 256 MB input standard input o ...
- node.js调用google翻译api
源码下载:https://pan.baidu.com/s/1nxoodst 使用:(只支持get) http://39.106.33.56:3001/translate?text=Failure is ...
- test-overflow:ellipsis的应用----转载
关键字: text-overflow:ellipsis 语法:text-overflow : clip | ellipsis 取值: clip :默认值 .不显示省略标记(...),而是简单的裁切. ...
- node 安装 vue-cli 创建vue项目
$ npm install -g vue-cli $ vue init webpack-simple my-project $ cd my-project $ npm install $ npm ru ...
- Python查看与安装
官网下载最新的版本 https://www.python.org mac系统,最近版本的os系统默认自带python 2.7,可以通过在终端输入python或python -V zhanyunjiu ...
- Linux常用内核参数
Linux常用内核参数 TCP状态描述 CLOSED:无连接是活动的或正在进行的 LISTEN:服务器在等待进入呼叫 SYN-RECV:一个连接请求已经到达,等待确认 SYN-SENT:应用已经开始, ...
- Binary Tree Path Sum
Given a binary tree, find all paths that sum of the nodes in the path equals to a given number targe ...
- angualr Material Icons
首先需要项目引入 angualr meterial icons的资源库 图标资源链接 https://klarsys.github.io/angular-material-icons/ <md- ...
- Java 获取class method parameter name
package org.rx.util; import org.objectweb.asm.*; import java.io.IOException; import java.io.InputStr ...