其实我没看懂题不如说根本没看--都说是excrt板子那就写个板子吧 注意开long long #include<iostream> #include<cstdio> using namespace std; const long long N=100005; long long n,r[N],m[N]; void exgcd(long long a,long long b,long long &d,long long &x,long long &y) { i…
题目链接 [VJ传送门] 题目描述 给你\(a_1...a_n\)和\(m_1...m_n\),求一个最小的正整数\(x\),满足\(\forall i\in[1,n] \equiv a_i(mod \ mi)\). 分析 很显然,中国剩余定理无法解决\(m_i\)之间非互质的问题. 需要用\(exCRT\). 假设\(x\)是前\(k-1\)个方程推出来的答案,那么第一个方程可以直接得出自己的答案就是\(a_1\). 设\(M=lcm(m_1,m_2...m_{k-1})\),那么显然得到\(…
题目大意 就是模板...没啥好说的 思路 因为模数不互质,所以直接中国剩余定理肯定是不对的 然后就考虑怎么合并两个同余方程 \(ans = a_1 + x_1 * m_1 = a_2 + x_2 * m_2\) \(x_1 * m_1 + x_2 * m_2 = a _ 2 - a _ 1\)(因为正负号没影响嘛) 然后就可以exgcd解出来\(x_1, x_2\), 最后就可以得到\(x' = a_1 + x_1 * m_1, m' = lcm(m_1, m_2)\) 然后就不停合并就可以了…
求解方程组 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…
扩展中国剩余定理板子 #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…
1635:[例 5]Strange Way to Express Integers sol:貌似就是曹冲养猪的加强版,初看感觉非常没有思路,经过一番艰辛的***,得到以下的结果 随便解释下给以后的自己听:K是要求的数字 第一个读入的A1,Mod1不用改,从2开始做,把Mod2改成LCM,A2改成Ans,接着搞3 /* 原式: X = A[1] (%Mod[1]) X = A[2] (%Mod[2]) ... X = A[n] (%Mod[n]) K[1]*Mod[1]+A[1] = X K[2]…
[POJ2891]Strange Way to Express Integers(拓展CRT) 题面 Vjudge 板子题. 题解 拓展\(CRT\)模板题. #include<iostream> #include<cstdio> using namespace std; #define ll long long #define MAX 111111 ll exgcd(ll a,ll b,ll &x,ll &y) { if(!b){x=1,y=0;return a;…
题意 Language:Default Strange Way to Express Integers Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 21651 Accepted: 7266 Description Elina is reading a book written by Rujia Liu, which introduces a strange way to express non-negative inte…
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 DescriptionElina 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 n…