先看题目:https://ac.nowcoder.com/acm/problem/16710
解题思路:
公式lcm(a,b) = ab / gcd(a,b)
记得要先a/gcd(a,b)然后再乘b以防止越界
*代码:**
#include<bits/stdc++.h> using namespace std; typedef unsigned long long ull; ull gcd(ull a, ull b) { return b == 0 ? a : gcd(b, a%b); } int main() { ull a, b; cin >> a >> b; ull m = gcd(a, b); cout << a/m * b << endl; }