标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 12877 Accepted Submission(s): 5504
输入16 4,2倍b是8,它的最大公约数就变成8了,还符合题意吗? 所以16 4的正确答案应该是12.
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 using namespace std; 5 int gcd(int a, int b) 6 { 7 if(b == 0) 8 return a; 9 else 10 return gcd(b, a % b); 11 } 12 int main() 13 { 14 int t; 15 scanf("%d", &t); 16 while(t--) 17 { 18 int n, m; 19 scanf("%d %d", &n, &m); 20 int c = m * 2; 21 while(gcd(n, c) != m) 22 c += m; 23 printf("%d\n", c); 24 } 25 return 0; 26 }
标签:
原文地址:http://www.cnblogs.com/fengshun/p/4740393.html