# Find the first four consecutive numbers to have 4 distinct prime factors. from useful import primeList count = 1000 numThatMatch = 0 pList = primeList(20000) def primeFactorize (n) : primes = pList ret = [] for p in primes : while n % p == 0 : ret.append(p) n /= p if n == 1 : return ret return ret while True : count += 1 factors = set(primeFactorize(count)) print count, factors if len(factors) >= 4 : numThatMatch += 1 else : numThatMatch = 0 if numThatMatch == 4 : print count break
# Find the sum of all 0 to 9 pandigital primes where # d2-4 is divisible by 2, d3-5 is divisible by 3, d4-6 is divisible by 5 # and so on through the primes from useful import digits, primeList, digitsToNum primes = primeList(18) sum = [0] def satisfies(threeDigs, primeIndex, allDigsSoFar) : if primeIndex == 0 : if threeDigs % 2 == 0 and len(set(allDigsSoFar)) == 9 : count = 0 while (count < 10) : if count not in allDigsSoFar : break count += 1 val = digitsToNum([count] + allDigsSoFar) print val sum[0] += val lastTwoDigs = threeDigs/10 for i in range(10) : if (i * 100 + lastTwoDigs) % primes[primeIndex-1] == 0 and i not in allDigsSoFar : satisfies(i*100+lastTwoDigs, primeIndex-1, [i] + allDigsSoFar) for j in range(6,59) : digs = digits(j*17,3) if len(set(digs)) == 3: satisfies(j*17,6,digs) print sum
# Find the prime below 1 000 000 that can be written as the longest sum of consecutive primes from useful import primeList, SortedList primes = primeList(1000000) primes = SortedList(primes) for i in range(547,0,-1) : for j in range(len(primes)-i) : #print "\t", j s = sum(primes[j:j+i]) if s > 1000000 : break if s in primes : print s, primes[j:j+i] exit()
# Find the first odd composite number that cannot be written as the sum of a prime and two times a square. from useful import primeList from math import sqrt pList = primeList(100000) c = 7 while True: c += 2 if c > 100000: break if c in pList: continue else: for p in pList: if int(sqrt((c - p) / 2)) ** 2 == (c - p) / 2: break else: print c break