最大公约数和最小公倍数

首先,最小公倍数=最大公约数*max。

那么,如何求最大公约数呢?

辗转相除法:类似这种常用的代码块应该记住

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <string>
 4 #include <string.h>
 5 typedef long long ll;
 6 using namespace std;
 7 int gcb(int a, int b) {
 8     if(a%b == 0) {
 9         return b;
10     }
11     return gcb(b, a%b); 
12 }
13 int main()
14 {
15     int a, b;
16     cin >> a >> b;
17     int x = gcb(a, b);
18     cout << x; 
19 }
原文地址:https://www.cnblogs.com/wzy-blogs/p/9163906.html