Exemple #1
0
# Find the sum of the prime factors of choose(20000000, 15000000)

from useful import PrimeList, primeFactorize

n = 20000000
r = 15000000

primes = PrimeList(n + 2)

toplist = range(15000001,20000001))
bottomlist = range(2,15000001)

topdict = {}
bottomdict = {}
for num in toplist :
  topdict[num] = 1
for num in bottomdict :
  bottomdict[num] = 1

for (num, count) in topdict.items() :
  
  total += sum(primeFactorize(num))
for num in bottomlist :
  print num
  total -= sum(primeFactorize(num))

print total
Exemple #2
0
# Find all numbers x that can be factored into x=ab such that x, a, and b contain each digit 1 through 9 exactly once.

# Let us generate all 4 or 5-digit numbers that are composed of unique digits.

from useful import primeFactorize, digits
				
sum = 0
for i in range (1000, 10000) :
	dList = digits(i)
	if (len(set(dList)) != len(dList) or 0 in dList) :
		continue
	factors = primeFactorize(i)
	for j in range(2**len(factors)) :
		num1 = 1
		num2 = 1
		for k in range(len(factors)) :
			if j/(k+1) == 1 :
				num1 *= factors[k]
			else :
				num2 *= factors[k]
		allDigits = dList + digits(num1) + digits(num2)
		if (len(allDigits) == 9 and len(set(allDigits)) == 9 and 0 not in allDigits) :
			print i, num1, num2, "!"
			sum += i
			break

print sum
Exemple #3
0
from useful import primeFactorize

dict = {}

for x in xrange(2,100001) :
  facts = primeFactorize(x)
  rad = frozenset(facts)
  if rad in dict :
    dict[rad].append(x)
  else :
    dict[rad] = [x]

tosort = []

for key in dict.keys() :
  prod = 1
  for fact in key :
    prod *= fact
  tosort.append((prod, key))

tosort.sort()

lower = 0
target = 10000

for (prod, rad) in tosort :
  if (lower + len(dict[rad]) < target) :
    lower += len(dict[rad])
    continue
  lis = dict[rad]
  lis.sort()