1/* 2 * mian. C 3 * C14-loop-14. max common approx. And Min. Public multiples 4 * created on: August 1, 2014 5 * Author: boomkeeper 6 ******** passed the test *********** 7 */8 9 # include <stdio. h> 10 11/** 12 * maximum common approx. 13 */14 int greatestcommondivisor (int m, int N) {15 int I; 16 for (I = (M <n? M: N); I> 1; I --) {17 if (M % I = 0 & N % I = 0) 18 break; 19} 20 return I; 21} 22 23/** 24 * min. Public multiple 25 */26 int leastcommonmultiple (int m, int N) {27 int I; 28 for (I = (M> n? M: N); I <= m * n; I ++) {29 If (I % m = 0 & I % N = 0) 30 break; 31} 32 return I; 33} 34 35 int main (void) {36 37 int M, N; // M n38 39 scanf ("% d ", & M, & N); 40 printf ("% d \ n", greatestcommondivisor (m, n), leastcommonmultiple (m, n); 41 42 return 0; 43}
Reference:
Http://www.myexception.cn/other/1673775.html
Question link:
Http://pat.zju.edu.cn/contests/basic-programming/%E5%BE%AA%E7%8E%AF-14