题解 | #求最小公倍数#
求最小公倍数
https://www.nowcoder.com/practice/22948c2cad484e0291350abad86136c3
#include <algorithm> #include <iostream> #include <vector> using namespace std; int maxG(int a, int b){ int max0=1, zhenmax=1; int min0 =min(a, b); while (max0<=min0) { if (a%max0==0&&b%max0==0) { if (zhenmax<max0) { zhenmax=max0; } } max0++; } return zhenmax; } int main() { int a, b; while (cin >> a >> b) { // 注意 while 处理多个 case // cout << a + b << endl; } vector<int> ap; while (maxG(a, b)!=1) { ap.push_back(maxG(a,b)); // cout<<ap.back()<<endl; a=a/ap.back(); b=b/ap.back(); } int output=1; for(auto x:ap){ output=output*x; } cout<<output*a*b; } // 64 位输出请用 printf("%lld")