zoj1091 python
时间: 2024-06-04 08:05:14 浏览: 94
code91.py
zoj1091是一道算法题,题目的完整描述可以在ZOJ(浙江大学在线评测系统)上找到。这道题的题目描述如下:
有一个不超过10^9的正整数n,求它的约数个数。
题目链接:https://zoj.pintia.cn/problem-sets/91827364500/problems/91827364653
这是一道数论题,求一个正整数的约数个数,可以通过对其质因数分解来求解。在Python中可以使用如下代码进行分解并计算约数个数:
```python
def factorize(n):
factors = []
d = 2
while d*d <= n:
while (n % d) == 0:
factors.append(d)
n //= d
d += 1
if n > 1:
factors.append(n)
return factors
def count_divisors(n):
factors = factorize(n)
count = 1
prev = factors
power = 1
for i in range(1, len(factors)):
if factors[i] == prev:
power += 1
else:
count *= (power+1)
prev = factors[i]
power = 1
count *= (power+1)
return count
n = int(input())
print(count_divisors(n))
```
阅读全文