mirror of
https://github.com/correl/euler.git
synced 2024-12-24 11:50:51 +00:00
Completed problem 012
git-svn-id: file:///srv/svn/euler@37 e5f4c3ec-3c0c-11df-b522-21efaa4426b5
This commit is contained in:
parent
d29322f502
commit
cb0cd33bfa
1 changed files with 12 additions and 4 deletions
16
e012.py
16
e012.py
|
@ -22,15 +22,23 @@ def product(l):
|
|||
|
||||
def factor(n):
|
||||
primes = pfactor(n)
|
||||
factors = []
|
||||
factors = [1, n]
|
||||
pow = {}
|
||||
for p in primes:
|
||||
if p not in pow.keys():
|
||||
pow[p] = 0
|
||||
pow[p] = pow[p] + 1
|
||||
factors.append(p**pow[p])
|
||||
for p in [f for f in factors if f < n / 2]:
|
||||
factors.append(n / p)
|
||||
|
||||
for p in [f for f in factors if f > 1]:
|
||||
f = n / p
|
||||
if f not in factors:
|
||||
factors.append(n / p)
|
||||
combos = unique_combinations(factors, 2)
|
||||
for c in combos:
|
||||
f = product(c)
|
||||
if f < n and n % f == 0 and f not in factors:
|
||||
factors.append(f)
|
||||
|
||||
if n not in factors:
|
||||
factors.append(n)
|
||||
|
@ -42,7 +50,7 @@ if __name__ == '__main__':
|
|||
i = i + 1
|
||||
t = triangle(i)
|
||||
f = factor(t)
|
||||
print 'Checking triangle', i, t
|
||||
print 'Checking triangle', i, t, len(f)
|
||||
if len(f) > 500:
|
||||
break
|
||||
|
||||
|
|
Loading…
Reference in a new issue