首页 > 代码库 > GCD AND LCM

GCD AND LCM

 1 #include <cstdio>
 2 __int64 GCD(__int64 a,__int64 b)
 3 {
 4     if (a % b == 0)
 5         return b;
 6     else
 7         return GCD(b,a%b);
 8 }
 9 __int64 LCM(__int64 a,__int64 b)        // a * b ==gcd*lcm 
10 {
11     return a / GCD(a,b) * b ;
12 }
13 int main()
14 {
15     __int64 a,b;
16     __int64 ans;
17     while (~scanf ("%I64d %I64d",&a,&b))
18     {
19         ans = LCM(a,b);
20         printf ("%I64d\n",ans);
21     }
22     return 0;
23 }

 

GCD AND LCM