最大公约数和最小公倍数

首先,最小公倍数=最大公约数*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 }

 

posted @ 2018-06-10 18:08  大帅妹妹  阅读(260)  评论(0编辑  收藏  举报