HDU 1222
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1222
是经典的求最大公约数的例子~~
代码如下:
1 #include <cstdio> 2 using namespace std; 3 4 long long m, n; 5 6 long gcd(long m, long n) 7 { 8 if(m < n) 9 { 10 m = m - n; 11 n = m + n; 12 m = n - m; 13 } 14 if(n == 0) 15 { 16 return m; 17 } 18 else 19 { 20 return gcd(n, m % n); 21 } 22 } 23 24 int main() 25 { 26 int t; 27 while(scanf("%d", &t) != EOF) 28 { 29 for(int i = 0; i < t; i++) 30 { 31 scanf("%lld %lld", &m, &n); 32 33 if(gcd(m, n) == 1) 34 { 35 printf("NO\n"); 36 } 37 else 38 { 39 printf("YES\n"); 40 } 41 } 42 } 43 return 0; 44 }