写一段python代码质因数分解
时间: 2023-04-06 17:03:13 浏览: 82
python简单实例训练(21~30)
以下是Python代码质因数分解:
```python
def prime_factors(n):
i = 2
factors = []
while i * i <= n:
if n % i:
i += 1
else:
n //= i
factors.append(i)
if n > 1:
factors.append(n)
return factors
print(prime_factors(123456789))
```
输出结果为:
```
[3, 3, 3607, 3803]
```
阅读全文