Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,13 +1,18 @@
|
|||
def factor(n):
|
||||
a, r = 1, [1]
|
||||
while a * a < n:
|
||||
a += 1
|
||||
if n % a: continue
|
||||
b, f = 1, []
|
||||
while n % a == 0:
|
||||
n //= a
|
||||
b *= a
|
||||
f += [i * b for i in r]
|
||||
r += f
|
||||
if n > 1: r += [i * n for i in r]
|
||||
return r
|
||||
from itertools import chain, cycle, accumulate # last of which is Python 3 only
|
||||
|
||||
def factors(n):
|
||||
def prime_powers(n):
|
||||
# c goes through 2, 3, 5, then the infinite (6n+1, 6n+5) series
|
||||
for c in accumulate(chain([2, 1, 2], cycle([2,4]))):
|
||||
if c*c > n: break
|
||||
if n%c: continue
|
||||
d,p = (), c
|
||||
while not n%c:
|
||||
n,p,d = n//c, p*c, d + (p,)
|
||||
yield(d)
|
||||
if n > 1: yield((n,))
|
||||
|
||||
r = [1]
|
||||
for e in prime_powers(n):
|
||||
r += [a*b for a in r for b in e]
|
||||
return r
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue