codeup 2135 least common multiple c++

c++ compilation

#include <iostream>
#include <stdio.h>

using namespace std;
int gcd(int a,int b){
    
    
   if(b==0)
    return a;
   else
    return gcd(b,a%b);
  }

int main()
{
    
    
  int a,b;
  while(scanf("%d%d",&a,&b)!=EOF){
    
     //EOF可以用-1来代替
      cout<<a*b/gcd(a,b)<<endl;
  }
    return 0;
}

Note: On the basis of finding the greatest common divisor d, the least common multiple is a*b/d to prevent overflow and can be written as a/d*b.

Guess you like

Origin blog.csdn.net/weixin_43902941/article/details/105949071