Skip to content

Commit

Permalink
feat(p12): add solution in python
Browse files Browse the repository at this point in the history
  • Loading branch information
pmpknu committed Oct 11, 2024
1 parent ea4285e commit 373fef7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions p12/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import math

def count_divisors(n):
sqrt_n = int(math.sqrt(n))
count = sum(2 for i in range(1, sqrt_n + 1) if n % i == 0)
if sqrt_n * sqrt_n == n:
count -= 1
return count

def first_triangle_number_with_divisors(limit):
n = 1
triangle = 1
while True:
divisors = count_divisors(triangle)
if divisors > limit:
return triangle
n += 1
triangle += n

limit = 500
result = first_triangle_number_with_divisors(limit)
print(result)

0 comments on commit 373fef7

Please sign in to comment.