示例#1
0
def genFactors(l = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29], maximum=10**10):
	exp = {}
	n = maximum
	# 1 until
	q = random.choice(l)
	one = 1
	for p in l:
		try: 
			exp[p] = random.randint(one,maxExponent(p,n))
		except:
			exp[p] = 0
		n //= p**exp[p]
		if p == q:
			one = 0
	phi = product([p**exp[p] - p**(exp[p] - 1) for p in l if exp[p] > 0])
	return phi, product([p**exp[p] for p in l])
示例#2
0
def problem124():
	checker = primes(save=True,initial=False)
	unsorted = [(1,1)]
	for c in generateFactors(100000,checker):
		unsorted.append((radFromFactors(c),product(c)))
	# Python already sorts list of tuples as first index first, second index in case of ties
	# so we use this by adding the elements rad(n) first
	unsorted.sort()
	return unsorted[10000-1][1]
示例#3
0
def problem179():
	GOAL = 10**7
	checker = primes(save=True,initial=False)
	#primes = rwh_primes2(GOAL//2)
	previous = 0
	# counting 2
	count = 0
	d = {1:1}
	for n in generateFactors(GOAL+1, checker):
		d[product(n)] = sigmaFromFactors(n)
	for n in range(1,GOAL):
		if d[n] == d[n+1]: count+=1
	return count
示例#4
0
def sigma(n,primes):
	l = factors(n,primes)
	return product([l.count(p) + 1 for p in set(l)])
示例#5
0
def divisible7(n):
	base = base7(n)
	return product( 6 - a for a in base[1:] )