Nuggets team number online, help you Offer impromptu! Click for details

I. Title Description:

Ii. Analysis of Ideas:

There are many ways to find the least common multiple, and here is one: Let the greatest common factor be C.

So A is equal to xc, B is equal to yc

Since x and y are mutually prime, the greatest common factor is xyc, i.e. A×Bc\frac{A \times B}{c}cA×B

Iii. AC Code:

#include<stdio.h>
#include<iostream>
using namespace std;

int main(a){
    int A, B;
    cin >> A >> B;
    
    int a = A,b = B;
    while(b ! =0) {int tmp = b;
        b = a % b;
        a = tmp;
    }
    cout << A*B/a << endl;
}
Copy the code

Iv. Summary:

I actually did it for recursion, and it just came out, which is kind of awkward

#include<stdio.h>
#include<iostream>
using namespace std;
int gdc(int a, int b){
    if(b == 0)return a;
    return gdc(b, a%b);
    
}
int main(a){
    int A, B;
    cin >> A >> B;
    
    int a = A,b = B;
    
    cout << A*B/ gdc(a,b) << endl;
}


Copy the code

If you look at the time, it recurses faster