首页 技术 正文
技术 2022年11月21日
0 收藏 697 点赞 3,231 浏览 859 个字
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;const int MaxM=11;int a[MaxM],b[MaxM];void exgcd(int a,int b,int &d,int &x,int &y){
if(b==0){
x=1; y=0;
d=a;
}
else{
exgcd(b,a%b,d,x,y);
int tmp=x;
x=y;
y=tmp-(a/b)*y;
}
}int gcd(int a,int b){
if(b==0) return a;
return gcd(b,a%b);
}int main(){
int t; int a1,r1,a2,r2; int aa,bb,cc,dd; int x,y; int g;
scanf("%d",&t);
int n,m;
bool ifhave;
int kase=0;
while(t--){
kase++;
scanf("%d",&m);
g=1;
for(int i=0;i<m;i++){
scanf("%d",&a[i]);
if(i==0){ g=a[i]; continue; }
g=g*a[i]/gcd(g,a[i]);
}
for(int i=0;i<m;i++)
scanf("%d",&b[i]);
a1=a[0]; r1=b[0];
ifhave=true;
for(int i=1;i<m;i++){
a2=a[i]; r2=b[i];
aa=a1; bb=a2; cc=r2-r1;
exgcd(aa,bb,dd,x,y);
if(cc%dd!=0){
ifhave=false;
break;
}
int t=bb/dd;
x=(x*(cc/dd)%t+t)%t;
r1=a1*x+r1;
a1=a1*(a2/dd);
}
printf("Case %d: ",kase);
if(!ifhave)
printf("-1\n");
else{
if(r1==0)
printf("%d\n",g);
else printf("%d\n",r1);
}
}
return 0;
}

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,999
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,357
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,140
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848