直接上递归版gcd模板,直接while的话效率更高~
1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 5 int gcd(int a, int b) { 6 return a % b ? gcd(b, a % b) : b; 7 } 8 9 int main() { 10 int a, b; 11 while(cin >> a >> b) { 12 int c = gcd(a, b); 13 cout << a / c * b << endl; 14 } 15 return 0; 16 }
时间: 2024-12-23 04:19:33