#include<iostream>
using namespace std;
int main(){
long A,B,a,b;
while(cin >> A >> B){
a = A;
b = B;
if(a < b){
long temp = a;
a = b;
b = temp;
}
while(b != 0){
long temp = b;
b = a % b;
a = temp;
}
cout << A * B / a << endl;
}
return 0;
}
Least Common Multiple
#include<iostream>
using namespace std;
long gcd(long a,long b){
if(a < b){
long temp = a;
a = b;
b = temp;
}
while(b != 0){
long temp = b;
b = a % b;
a = temp;
}
return a;
}
int main(){
long x[100];
int n,m,i;
while(cin >> n){
while(n--){
cin >> m;
for(i=0;i<m;i++)
cin >> x[i];
for(i=0;i<m-1;i++)
x[i+1] = x[i] * x[i+1] / gcd(x[i],x[i+1]);
cout << x[m-1] << endl;
}
}
return 0;
}
最小公倍数(LCM)例4.5 最小公倍数代码4.7#include<iostream>using namespace std;int main(){ long A,B,a,b; while(cin >> A >> B){ a = A; b = B; if(a < b){ long temp = a; a = b; ...