题目链接 题意:给k对数,每对ai, ri.求一个最小的m值,令m%ai = ri; 分析:由于ai并不是两两互质的, 所以不能用中国剩余定理. 只能两个两个的求. a1*x+r1=m=a2*y+r2联立得:a1*x-a2*y=r2-r1;设r=r2-r2; 互质的模线性方程组m=r[i](mod a[i]).两个方程可以合并为一个,新的a1为lcm(a1,a2), 新的r为关于当前两个方程的解m,然后再和下一个方程合并…….(r2-r1)不能被gcd(a1,a2)整除时无解.   怎么推出的看…
题目链接 扩展中国剩余定理:1(直观的).2(详细证明). [Upd:]https://www.luogu.org/problemnew/solution/P4774 #include <cstdio> #include <cctype> #define gc() getchar() typedef long long LL; const int N=1e6+5; LL n,m[N],r[N]; inline LL read() { LL now=0,f=1;register ch…
题目链接 扩展CRT模板题,原理及证明见传送门(引用) #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; ; ll n,m[N],c[N]; void exgcd(ll a,ll b,ll& x,ll& y,ll& g) { ,y=,g=a; else exgcd(b,a%b,y,x,g),y-=x*(a/b); } bool CRT(ll&…
Strange Way to Express Integers Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 9472   Accepted: 2873 Description Elina is reading a book written by Rujia Liu, which introduces a strange way to express non-negative integers. The way is…
Strange Way to Express Integers Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 16839   Accepted: 5625 Description Elina is reading a book written by Rujia Liu, which introduces a strange way to express non-negative integers. The way is…
Strange Way to Express Integers Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 10907   Accepted: 3336 Description Elina is reading a book written by Rujia Liu, which introduces a strange way to express non-negative integers. The way is…
Description Elina is reading a book written by Rujia Liu, which introduces a strange way to express non-negative integers. The way is described as following: Choose k different positive integers a1, a2, …, ak. For some non-negative m, divide it by ev…
题目链接:http://poj.org/problem?id=2891 题目大意: 求解同余方程组,不保证模数互质 题解: 扩展中国剩余定理板子题 #include<algorithm> #include<cstring> #include<cstdio> #include<iostream> #include<cmath> using namespace std; typedef long long ll; +; int k; ll m[N],…
扩展中国剩余定理板子 #include<iostream> #include<cstdio> using namespace std; const int N=100005; int n; long long m[N],r[N],M,R,x,y,d; void exgcd(long long a,long long b,long long &d,long long &x,long long &y) { if(!b) { d=a,x=1,y=0; return…
求解方程组 X%m1=r1 X%m2=r2 .... X%mn=rn 首先看下两个式子的情况 X%m1=r1 X%m2=r2 联立可得 m1*x+m2*y=r2-r1 用ex_gcd求得一个特解x' 得到X=x'*m1+r2 X的通解X'=X+k*LCM(m1,m2) 上式可化为:X'%LCM(m1,m2)=X 到此即完成了两个式子的合并,再将此式子与后边的式子合并,最后的得到的X'即为答案的通解,求最小整数解即可. #include<stdio.h> #include<string.h…