HDUOJ---hello Kiki
发布日期:2021-09-08 01:44:56 浏览次数:38 分类:技术文章

本文共 2265 字,大约阅读时间需要 7 分钟。

Hello Kiki

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1717    Accepted Submission(s): 599

Problem Description
One day I was shopping in the supermarket. There was a cashier counting coins seriously when a little kid running and singing "门前大桥下游过一群鸭,快来快来 数一数,二四六七八". 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.
 
Input
The 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
 
Output
For 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
2
2
14 57
5 56
5
19 54 40 24 80
11 2 36 20 76
 
Sample Output
Case 1: 341
Case 2: 5996
 
Author
digiter (Special Thanks echo)
 
Source
 
Recommend
zhouzeyong
中国剩余定理:
该题典型的同余方程组X=amod(M)求解,需要注意的是,题目要求最小的的整数解,所以如果解为0是,他们的最小解为他们的最小公倍数..lcm
代码:
1 #include
2 #include
3 #define LL _int64 //long long 4 using namespace std; 5 LL x,y,q; 6 LL gcd(LL a,LL b) 7 { 8 if(b==0) 9 return gcd(b,a%b);10 else 11 return a;12 }13 14 void exgcd( LL a, LL b)15 {16 if(b==0)17 x=1,y=0,q=a;18 else19 {20 exgcd(b,a%b);21 LL temp=x;22 x=y,y=temp-a/b*y;23 }24 }25 26 int main()27 {28 int ncase,n,i,j;29 LL lcm,aa[10],rr[10];30 bool ifhave;31 // freopen("test.in","r",stdin);32 //freopen("test.out","w",stdout);33 scanf("%d",&ncase);34 for(j=1;j<=ncase;j++)35 { 36 scanf("%d",&n);37 lcm=1;38 ifhave=true;39 for(i=0;i
复制代码

 

 

转载地址:https://blog.csdn.net/weixin_34310369/article/details/85583376 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:也谈“穷家富养”和“富家穷养”_快乐杜鹃_新浪博客
下一篇:NSFileManager和NSFileHandle(附:获取文件大小 )

发表评论

最新留言

不错!
[***.144.177.141]2024年04月16日 14时05分11秒