【Codeforces Round #196 (Div. 1)】Codeforces 338D GCD Table
来源:互联网 发布:招商证券理财软件下载 编辑:程序博客网 时间:2024/05/23 13:25
题目实际上要求一组
首先可以找到
接下来考虑
接下来只需要把得到的
#include<cstdio>#include<algorithm>using namespace std;#define LL long longconst LL oo=1e17;LL a[10010];LL gcd(LL a,LL b){ return b?gcd(b,a%b):a;}LL mul(LL x,LL y){ double t=(double)x*y; if (t>oo) return oo; return x*y;}LL lcm(LL a,LL b){ return mul(a/gcd(a,b),b);}LL exgcd(LL a,LL b,LL &x,LL &y){ if (!b) { x=1; y=0; return a; } LL ret=exgcd(b,a%b,y,x); y-=a/b*x; return ret;}LL multi(LL base,LL k,LL mod){ if (k<0) { base=-base; k=-k; } LL ret=0; for (;k;k>>=1,base=(base+base)%mod) if (k&1) ret=(ret+base)%mod; return ret;}int main(){ LL n,m,x=1,u,v,v1,w,y,t1,t2,g; int k; scanf("%I64d%I64d%d",&n,&m,&k); for (int i=1;i<=k;i++) scanf("%I64d",&a[i]); for (int i=1;i<=k;i++) { x=lcm(x,a[i]); if (x>n) { printf("NO\n"); return 0; } } u=0; v=a[1]; for (int i=2;i<=k;i++) { g=exgcd(v,a[i],t1,t2); w=-u-i+1; if (w%g) { printf("NO\n"); return 0; } v1=v; v=v/g*a[i]; u=multi(multi(w/g,t1,v),v1,v)+u; u%=v; } y=(u+v)%v; if (!y) y+=v; if (y+k-1>m) { printf("NO\n"); return 0; } for (int i=1;i<=k;i++) if (gcd(x,y+i-1)!=a[i]) { printf("NO\n"); return 0; } printf("YES\n");}
0 0
- 【Codeforces Round #196 (Div. 1)】Codeforces 338D GCD Table
- Codeforces Round #323 (Div. 1) A. GCD Table stl应用
- codeforces 338D GCD Table
- codeforces 338D GCD Table
- Codeforces Round #140 (Div. 1)D The table 贪心
- Codeforces Round #323 (Div. 2) C.GCD Table
- Codeforces Round #323 (Div. 2)C. GCD Table
- Codeforces Round #323 (Div. 2) C. GCD Table
- Codeforces 338D GCD Table 题解&代码
- Codeforces Round #256 (Div. 2) D. Multiplication Table
- Codeforces Round #256 (Div. 2) D. Multiplication Table
- Codeforces Round #256 (Div. 2) D. Multiplication Table 二分
- Codeforces Round #256 (Div. 2) D. Multiplication Table
- Codeforces Round #256 (Div. 2) D. Multiplication Table
- Codeforces Round #256 (Div. 2) D. Multiplication Table
- Codeforces Round #256 (Div. 2) D Multiplication Table (二分)
- Codeforces Round #256 (Div. 2) D. Multiplication Table 【二分】
- codeforces Round 256(Div.2)D.Multiplication Table(二分)
- DRML(2016-CVPR)重现过程记录---(6)新的尝试与思考-tensorflow?
- Linux netstat 命令详解
- Hat's Words hdu1247 trie
- Qt环境搭建(Visual Studio)
- 简单的RPC(未用动态代理)
- 【Codeforces Round #196 (Div. 1)】Codeforces 338D GCD Table
- 正则表达式的圆括号和中括号的区别
- Qt环境搭建(Qt Creator)
- 按钮添加单机响应事件
- 关于MyEclipse导入工程后部分JS文件出现红叉不可用的情况及解决办法
- C++抽象编程——面向对象(7)——设计新的类(2)
- java垃圾回收(GC)
- C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets 64 5
- 标志位寄存器与CF、OF标志位的区分