调用函数求最大公约数和最小公倍数
时间: 2023-12-03 07:38:54 浏览: 105
求最大公约数和最小公倍数
以下是Python中调用函数求最大公约数和最小公倍数的例子:
1. 求最大公约数
```python
import math
num1 = 24
num2 = 36
gcd = math.gcd(num1, num2)
print("The GCD of", num1, "and", num2, "is", gcd) # 输出:The GCD of 24 and 36 is 12
```
2. 求最小公倍数
```python
import math
num1 = 24
num2 = 36
lcm = num1 * num2 // math.gcd(num1, num2)
print("The LCM of", num1, "and", num2, "is", lcm) # 输出:The LCM of 24 and 36 is 72
```
阅读全文