We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0ea5c73 commit 765be45Copy full SHA for 765be45
project_euler/problem_012/sol2.py
@@ -29,7 +29,18 @@ def triangle_number_generator():
29
30
31
def count_divisors(n):
32
- return sum(2 for i in range(1, int(n ** 0.5) + 1) if n % i == 0 and i * i != n)
+ divisors_count = 1
33
+ i = 2
34
+ while i * i <= n:
35
+ multiplicity = 0
36
+ while n % i == 0:
37
+ n //= i
38
+ multiplicity += 1
39
+ divisors_count *= multiplicity + 1
40
+ i += 1
41
+ if n > 1:
42
+ divisors_count *= 2
43
+ return divisors_count
44
45
46
def solution():
0 commit comments