Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
118133 | 冯诚阳 | 最大公约数和最小公倍数 | C++ | Accepted | 1 MS | 272 KB | 583 | 2025-04-24 18:44:27 |
#include <iostream> using namespace std; // 求最大公约数(Greatest Common Divisor) int gcd(int a, int b) { while (b != 0) { int temp = a % b; a = b; b = temp; } return a; } // 求最小公倍数(Least Common Multiple) int lcm(int a, int b) { return a * b / gcd(a, b); } int main() { int a, b; cin >> a >> b; // 确保a是较大的数,可以优化gcd的计算次数 if (a < b) { swap(a, b); } cout << gcd(a, b) << " " << lcm(a, b) << endl; return 0; }