国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

中國剩余定理(非互質(zhì))hdu3579 Hello Kiki ====注意剛好全部整除的情況

2019-11-06 06:28:13
字體:
供稿:網(wǎng)友

Hello Kiki

Time Limit: 2000/1000 MS (java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3578    Accepted Submission(s): 1334PRoblem DescriptionOne day I was shopping in the supermarket. There was a cashier counting coins seriously when a little kid running and singing "門前大橋下游過一群鴨,快來快來 數(shù)一數(shù),二四六七八". And then the cashier put the counted coins back morosely and count again...Hello Kiki is such a lovely girl that she loves doing counting in a different way. For example, when she is counting X coins, she count them N times. Each time she divide the coins into several same sized groups and write down the group size Mi and the number of the remaining coins Ai on her note.One day Kiki's father found her note and he wanted to know how much coins Kiki was counting. InputThe first line is T indicating the number of test cases.Each case contains N on the first line, Mi(1 <= i <= N) on the second line, and corresponding Ai(1 <= i <= N) on the third line.All numbers in the input and output are integers.1 <= T <= 100, 1 <= N <= 6, 1 <= Mi <= 50, 0 <= Ai < Mi OutputFor each case output the least positive integer X which Kiki was counting in the sample output format. If there is no solution then output -1. Sample Input
2214 575 56519 54 40 24 8011 2 36 20 76 Sample Output
Case 1: 341Case 2: 5996
#include<cstdio>#include<iostream>using namespace std;#define ll long longll g;void exgcd(ll a,ll b,ll& x,ll& y){	if(b==0){	g=a;	x=1;	y=0;		}	else{		exgcd(b,a%b,y,x);		y-=x*(a/b);	}}int main(){	ll n,a,m,mm[10],aa[10],k1,k2,c,T;	cin>>T;	for(int i=1;i<=T;i++){	int flag=1;	cin>>n;	for(int i=1;i<=n;i++)	cin>>mm[i];	for(int i=1;i<=n;i++)	cin>>aa[i];	cout<<"Case "<<i<<": ";	a=aa[1];	m=mm[1];	//m*k1+a=m[i]*k2+a[i]	for(int i=2;i<=n;i++){		c=aa[i]-a;		exgcd(m,mm[i],k1,k2);		if(c%g){			    flag=0;		    cout<<-1<<endl;			break;		}		k1=k1*c/g;		k1=(k1+mm[i]/g)%(mm[i]/g);		a=k1*m+a;		m=m*mm[i]/g;	}	if(flag)	{		a=(a+m)%m;		if(a)		cout<<a<<endl;		else		cout<<m<<endl;	}	}	return 0;}

 


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 新宁县| 辰溪县| 平武县| 巴林左旗| 丹凤县| 娄底市| 汶上县| 桃江县| 依兰县| 定西市| 普宁市| 西丰县| 曲靖市| 太湖县| 武鸣县| 陵水| 永康市| 平南县| 论坛| 循化| 甘孜县| 田林县| 宁城县| 开鲁县| 平安县| 濉溪县| 昌宁县| 马山县| 逊克县| 日喀则市| 聂拉木县| 德州市| 疏勒县| 梁山县| 舞阳县| 鲁甸县| 辽源市| 南木林县| 望都县| 金昌市| 建昌县|