【中国剩余定理模板】
2014-07-17 14:58
204 查看
LL a[maxn], b[maxn], n; void extend_gcd(LL a, LL b, LL &d, LL &x, LL &y) { if(b == 0) { d = a, x = 1, y = 0; } else { extend_gcd(b, a%b, d, y, x), y -= x*(a/b); } } void extend_chinese_reminder(LL &a1, LL &b1) { LL x, y, g, tmp, i, a2, b2; for(i = 1; i < n; i++) { a2 = a[i], b2 = b[i]; extend_gcd(a1, a2, g, x, y); tmp = a2/g; x = x*(b2-b1)/g; x = (x%tmp+tmp)%tmp; b1 = a1*x+b1; a1 = (a1*a2)/g; b1 = (b1%a1+a1)%a1; } } //最后传出去的a1代表循环节,b1代表最小正解
相关文章推荐
- 中国剩余定理模板
- 【模板】【POJ2891】扩展中国剩余定理
- 中国剩余定理模板题 互质与非互质
- hdu 1573 X问题 中国剩余定理(直接模板就OK了)
- poj 1006 中国剩余定理模板
- poj 1006 中国剩余定理模板
- 中国剩余定理模板(1) 两两互质情况
- 中国剩余定理(模板+代码)
- 中国剩余定理模板(互质的情况)
- POJ 2891 Strange Way to Express Integers 【中国剩余定理线性模方程合并(模板)】
- 中国剩余定理模板
- poj 1006 中国剩余定理模板
- 中国剩余定理模板(2)出现不互质情况
- 扩展中国剩余定理模板
- poj 1006 中国剩余定理模板
- 中国剩余定理模板
- poj 1006 中国剩余定理模板
- LightOJ - 1319 Monkey Tradition (中国剩余定理 模板)
- 中国剩余定理模板
- 中国剩余定理的_非互素同余模板