最大公倍数,最小公约数

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <algorithm>
  4. #include <iostream>
  5. using namespace std;
  6. //int f[1010]= {0, 1, 1};
  7. __int64 lcm(__int64 a,__int64 b) // 最小公倍数
  8. {
  9. __int64 c = b%a;
  10. if(a > b) return lcm(b, a);
  11. if(c==0) return b;
  12. return lcm(c,a)/c*b;
  13. }
  14. __int64 gcd(__int64 x, __int64 y) //最大公约数
  15. {
  16. __int64 m;
  17. if(x<y)
  18. return gcd(y,x);
  19. if(x%y!=0)
  20. return gcd(y,x%y);
  21. else return y;
  22. }





附件列表

    原文地址:https://www.cnblogs.com/sober-reflection/p/1424dfd0405240e68dd7565f8a3cfca4.html