See GCD again.Time
limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 15221 Accepted Submission (s): 6397
Problem description has three positive integers a,b,c (0<a,b,c<10^6), where c is not equal to B. If the greatest common divisor of a and C are B, it is now known A and b to satisfy the minimum c of the condition.
Input the first line to enter an n, indicating that there are n sets of test data, the next n rows, each line entered two positive integers, a, a.
The output outputs correspond to C, one row for each set of test data.
Sample Input
26 212 4
Sample Output
48
Source "ACM Program Design" Short Semester exam _ software engineering and other major
original title link: http://acm.hdu.edu.cn/showproblem.php?pid=2504Analysis:know that the a,c greatest common divisor B, known as A, a, the smallest c is known as GCD (a,c) = B, the smallest C. Do not be naïve to think that c=2b;can not be ignored is that the topic requires b! = C, that is, the C value starts from 2b, and then step by step c and then determine whether the a,c greatest common divisor is equal to B, the output C when satisfied.
AC Code:
#include <iostream>using namespace Std;int GCD (int x,int y) { return y==0?x:gcd (y,x%y);} int main () { int t,a,b; cin>>t; while (t--) { cin>>a>>b; int c = 2*b; while (GCD (a,c)!=b) { c+=b; } cout<<c<<endl; } return 0;}
HDU 2054 See also GCD (water problem??)