在线模板_中国剩余定理
2018-02-04 21:37
316 查看
在线模板_中国剩余定理
模板例题51nod1079//chu是除数,yu是余数 //注意只适用于除数两两互质 #include<iostream> #include<queue> using namespace std; typedef long long ll; ll extended_euclid(ll a, ll b, ll &x, ll &y) { ll d; if(b == 0) {x = 1; y = 0; return a;} d = extended_euclid(b, a % b, y, x); y -= a / b * x; return d; } ll chinese_remainder(ll b[], ll w[], ll len) { ll i, d, x, y, m, n, ret; ret = 0; n = 1; for(i=0; i < len ;i++) n *= w[i]; for(i=0; i < len ;i++) { m = n / w[i]; d = extended_euclid(w[i], m, x, y); ret = (ret + y*m*b[i]) % n; } return (n + ret%n) % n; } ll yu[100],chu[100]; int main() { ll n; while(cin>>n) { for(ll i=0;i<n;i++) { cin>>chu[i]>>yu[i]; } ll ans=chinese_remainder(yu,chu,n); cout<<ans<<endl; } return 0; }
相关文章推荐
- 中国剩余定理 模板
- poj 1006 中国剩余定理模板
- hdu 3579 Hello Kiki 中国剩余定理(不互质形式)模板题
- 中国剩余定理模板(1) 两两互质情况
- poj 1006中国剩余定理(模板题)
- 中国剩余定理(模板)
- poj 1006 中国剩余定理模板
- 中国剩余定理模板(2)出现不互质情况
- 中国剩余定理模板(互质版和非互质版)
- 【模板】【codevs3990】中国剩余定理
- 求解一次同余式和中国剩余定理的模板
- poj 1006 中国剩余定理模板
- 中国剩余定理模板(互质的情况)
- 【模板】【POJ2891】扩展中国剩余定理
- poj 1006 中国剩余定理模板
- 中国剩余定理模板
- poj 1006 中国剩余定理模板
- 数论快速入门(同余、扩展欧几里德、中国剩余定理、大素数测定和整数分解、素数三种筛法、欧拉函数以及各种模板)
- 欧拉函数、中国剩余定理背诵用模板
- poj 1006 中国剩余定理模板