1.欧几里得辗转相除法

 1 #include <iostream>
 2 #include <algorithm>
 3 
 4 using namespace std;
 5 
 6 int gcd(int a, int b){
 7     if(a < b)
 8         swap(a, b);
 9     return b == 0 ? a : gcd(b, a % b);
10 }

 2.最小公倍数

1 int lcm(int a, int b){
2     return a / gcd(a, b) * b;
3 }

 

相关文章:

  • 2021-12-19
  • 2021-08-16
  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2022-01-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
相关资源
相似解决方案