-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp0012.py
executable file
·69 lines (52 loc) · 1.36 KB
/
p0012.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/local/bin/python
import getopt, sys, math
from sets import Set
def main():
number = 4
opt, args = getopt.getopt(sys.argv[1:], ':n:')
for o, a in opt:
if o == '-n':
number = int(a)
else:
assert False, "unhandled option"
total = 0
inc = 0
cur_max = 0
while True:
inc += 1
total += inc
factors = primes(total)
#print "{}: {}".format(total, factors)
count = test(factors)
if count > cur_max:
cur_max = count
print "{}, {}: {}".format(inc, total, count)
#print "{}: {}".format(total, count)
if count > number:
print "{}: {}".format(total, count)
break
# I guess this is a divisor or tau function
def test(factors):
primecounts = {}
for prime in factors:
if prime in primecounts:
primecounts[prime] += 1
else:
primecounts[prime] = 1
total = 1
for primecount in primecounts:
total *= (primecounts[primecount] + 1)
return total
def primes(n):
primfac = []
d = 2
while d*d <= n:
while (n % d) == 0:
primfac.append(d) # supposing you want multiple factors repeated
n //= d
d += 1
if n > 1:
primfac.append(n)
return primfac
if __name__ == "__main__":
main()