fzu 1402 中国剩余定理 http://acm.fzu.edu.cn/problem.php?pid=1402
2012-12-07 20:37
351 查看
//两两互质。 #include<stdio.h> #include<string.h> #define in __int64 in num1[15]; in num2[15]; in ext_Euclid(in a,in b,in &x,in &y) { if(b==0) { x=1; y=0; return a; } in d=ext_Euclid(b,a%b,x,y); in tem=x; x=y; y=tem-a/b*y; return d; } in China_Reminder(int len,in* n,in* a) { in result=0; in N=1; int i,j; for(i=0; i<len; i++) N=N*n[i]; for(j=0; j<len; j++) { in m=N/n[j]; in x,y; ext_Euclid(m,n[j],x,y); // printf("x=%I64d\n",x); x=(x%n[j]+n[j])%n[j]; result = (result + m*a[j]*x%N)%N; } return result; } int main() { int n; while(scanf("%d",&n)!=EOF) { for(int i=0; i<n; i++) { scanf("%I64d%I64d",&num1[i],&num2[i]); } printf("%I64d\n",China_Reminder(n,num1,num2)); } return 0; }
相关文章推荐
- Problem 1410 变位词 from http://acm.fzu.edu.cn/problem.php?pid=1410
- Problem 1057 ab from http://acm.fzu.edu.cn/problem.php?pid=1057
- Problem 1478 环形整数串 from http://acm.fzu.edu.cn/problem.php?pid=1478
- http://acm.fzu.edu.cn/problem.php?pid=2113 数位DP
- Problem 1582 众数问题 from http://acm.fzu.edu.cn/problem.php?pid=1582
- http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理
- Problem 1046 Tempter of the Bone, from http://acm.fzu.edu.cn/problem.php?pid=1046
- Problem 1453 Bignum Arithmetic from http://acm.fzu.edu.cn/problem.php?pid=1453
- http://acm.fzu.edu.cn/problem.php?pid=1564 C(n,k)和素数P的问题
- http://acm.hdu.edu.cn/showproblem.php?pid=4514
- http://acm.hdu.edu.cn/showproblem.php?pid=1568
- To The Max &&http://acm.hdu.edu.cn/showproblem.php?pid=1081
- Buy the Ticket&&http://acm.hdu.edu.cn/showproblem.php?pid=1133
- http://acm.hdu.edu.cn/showproblem.php?pid=1124 N!末尾0的个数
- http://acm.hdu.edu.cn/showproblem.php?pid=1905 素数判断 + 二分
- http://acm.hdu.edu.cn/showproblem.php?pid=3519
- Trouble&&http://acm.hdu.edu.cn/showproblem.php?pid=4334
- http://acm.hdu.edu.cn/showproblem.php?pid=1166
- http://acm.hdu.edu.cn/showproblem.php?pid=1722
- http://acm.hdu.edu.cn/showproblem.php?pid=1055&&Color a Tree