中国剩余定理
来源:互联网 发布:剑灵天女捏脸图文数据 编辑:程序博客网 时间:2024/06/05 16:49
https://vj.xtuacm.cf/contest/view.action?cid=57#problem/B
这题目除数互质,裸的模板
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <cstring>#include <vector>#include <set>#define ll long longusing namespace std;const int maxn=1020;ll a[maxn],b[maxn];void e_gcd(ll a,ll b,ll &x,ll &y){ if(b==0) { x=1; y=0; return ; } e_gcd(b,a%b,x,y); ll temp=x; x=y; y=temp-a/b*y; //return ans;}ll CRT(ll a[],ll b[],ll n){ ll M=1; ll ans=0; for(int i=0;i<n;i++) M*=a[i]; for(int i=0;i<n;i++) { ll x,y; ll mi=M/a[i]; e_gcd(mi,a[i],x,y); ans=(ans+mi*x*b[i])%M; } if(ans<0) ans+=M; return ans;}int main(){ int n; while(~scanf("%d",&n)) { for(int i=0;i<n;i++) scanf("%I64d%I64d",&a[i],&b[i]); ll ans=CRT(a,b,n); cout<<ans<<endl; } return 0;}
阅读全文
0 0
- 中国剩余定理模版【中国剩余定理】
- 中国剩余定理
- 中国剩余定理
- 中国剩余定理
- 中国剩余定理
- 中国剩余定理
- 中国剩余定理
- 中国剩余定理
- 中国剩余定理
- 数论-中国剩余定理
- 中国剩余定理
- 中国剩余定理
- 中国剩余定理
- 数论/中国剩余定理
- 关于《中国剩余定理》
- 中国剩余定理
- 模板[中国剩余定理]
- 中国剩余定理
- String与StringBuilder以及StringBuffer的比较
- 基于STM32F103的超声波测距
- Beijing 2008 HDU
- cpuid 的使用方法
- 【Linux】子进程的异步等待方式
- 中国剩余定理
- 内存管理笔记(分页,分段,逻辑地址,物理地址与地址转换方式)
- OFDM中的信道估计Channel Estimation
- 练习赛1(补题)
- python_selenium(sn)
- 数学问题——割圆法求π的近似值
- FTP
- ios-MRC下的@property的参数
- 进程地址空间(Linux内核源码分析)