同餘方程 hdu 3579
来源:互联网 发布:淘宝618大促 编辑:程序博客网 时间:2024/06/05 18:06
求特解
#include<stdio.h>#include<algorithm>using namespace std;int a[10],b[10];int n;int ex_gcd(int a,int b,int &x,int &y){ if(b==0) { x=1; y=0; return a; } int t,res; res=ex_gcd(b,a%b,x,y); t=x; x=y; y=t-(a/b)*y; return res;}int solo(){ int x,y,gcd,a1,a2,b1,b2,i,t; a1=a[0],b1=b[0]; for(i=1;i<n;i++) { a2=a[i]; b2=b[i]; gcd=ex_gcd(a1,a2,x,y); if((b2-b1)%gcd!=0) { return -1; } t=a2/gcd; x=(x*(b2-b1))/gcd; x=(x%t+t)%t; b1=a1*x+b1; a1=(a1*a2)/gcd; b1=(b1%a1+a1)%a1; } if(b1==0&&n>1) b1=a1; if(b1==0&&n==1) b1=a[0]; return b1;}int main(){ int t; scanf("%d",&t); for(int cs=1;cs<=t;cs++) { scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&a[i]); } for(int i=0;i<n;i++) { scanf("%d",&b[i]); } printf("Case %d: %d\n",cs,solo()); } return 0;}
0 0
- 同餘方程 hdu 3579
- 同餘方程 hdu 1573
- 同餘方程 poj1061
- hdu 3579 Hello Kiki(线性同余方程)
- HDU 5668:Circle 同余方程
- HDU 2815 Mod Tree 解高次同余方程
- hdu 2815 Mod Tree(高次同余方程)
- hdu 1573 X问题(线性同余方程)
- HDU 5114 Collision(一元线性同余方程)
- HDU 5755 Gambler Bo(高斯消元解同余方程)
- hdu 2815 Mod tree 高次同余方程
- HDU 5114 Collision(一元线性同余方程)
- 线性同余方程
- 解同余方程
- 线性同余方程
- 线性同余方程
- 线性同余方程
- 一次同余方程
- insmod: module 'hello.ko' not found
- 开发:随笔记录之 CXF 动态调用Webservice
- 吐槽做得很不错的ZeroClipboard
- Rosserial中模板类的使用。以NodeHandle定义说起,关注Hardware
- eclipse 常用快捷键
- 同餘方程 hdu 3579
- 算法基础-展开串
- Struts2文件上传下载
- ScrollView 与 viewpager冲突问题
- 运算符优先级总结
- HDU-1693 Eat the Trees 插头DP
- 一纪委书记大年夜操大年夜办婚庆被处奖
- ScrollView或者ListView中嵌套ViewPager,展示不出来问题。
- android Installation error: INSTALL_FAILED_CONTAINER_ERROR错误的处理