-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproblem12.py
More file actions
35 lines (32 loc) · 895 Bytes
/
problem12.py
File metadata and controls
35 lines (32 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import functools
# Find the prime factorization of the given number, returned as an array
def primes(n):
primfac = []
d = 2
while d*d <= n:
while (n % d) == 0:
primfac.append(d)
n /= d
d += 1
if n > 1:
primfac.append(n)
return primfac
# Number of factors is product of the (exponent + 1) of all prime factors
def num_factors(n):
prime_factors = primes(n)
exponents = []
while len(prime_factors) > 0:
next = prime_factors[0]
count = prime_factors.count(next)
exponents.append(count + 1)
prime_factors = [item for item in prime_factors if item != next]
return functools.reduce(lambda x, y: x*y, exponents)
#76576500
def answer():
x = 1
next_tri = 1
while True:
x += 1
next_tri += x
if num_factors(next_tri) > 500:
return next_tri