Message80605
Here's a couple of functions I use with count and step:
def cf_e():
'''return: (iterator) the infinite continued fraction for e
e=[2; 1, 2, 1, 1, 4, 1, 1, 6, 1 , ... , 1, 2k, 1, ...]
'''
yield 2
for k in itertools.count(2, 2):
yield 1
yield k
yield 1
def prime_factors(n):
'''n: (int > 1)
return: (list) the sorted list of tuples (p,e) of prime factors of n
p is a prime factor, e is the number of times the factor is used
'''
ret = []
if n <= 1:
return ret
# factors: use known (small) primes, then possible primes (odd numbers)
for factor in itertools.chain([2,3,5,7,11], itertools.count(13, 2)):
if factor*factor > n:
if n != 1:
ret += [(n, 1)]
break
for e in itertools.count(0):
div, mod = divmod(n, factor)
if mod != 0:
break
n = div
if e >= 1:
ret += [(factor, e)]
return ret |
|
Date |
User |
Action |
Args |
2009-01-27 01:42:19 | steve21 | set | recipients:
+ steve21, rhettinger, LambertDW |
2009-01-27 01:42:19 | steve21 | set | messageid: <1233020539.44.0.269039576151.issue5032@psf.upfronthosting.co.za> |
2009-01-27 01:42:17 | steve21 | link | issue5032 messages |
2009-01-27 01:42:17 | steve21 | create | |
|