import time from primes import divisors, factor, pfactor_gen START = time.time() SIZE = 10**6 factors = pfactor_gen(SIZE) for i in xrange(2,SIZE,2): if sum(divisors(i)) % i == i/2: print i, factor(i) print "Time Taken:", time.time() - START """ 2: 1,3,7,15,31,65,129 3: 1,4,10,40,121,364 5: 1,6,31,156,781,3906 p(2) = 3/2 -> 1 1/2 p(24) = (13 * 4)/8 = 6 1/2 p(4320) = (63 * 40 * 6) = 3 1/2 -> 2^4 * 3^3 * 5 * 7 4320 = 2^5 * 3^3 * 5 2 [2] 24 [2, 2, 2, 3] 4320 [2, 2, 2, 2, 2, 3, 3, 3, 5] 4680 [2, 2, 2, 3, 3, 5, 13]
import time, string from primes import pfactor_gen, factor_given_pfactor from itertools import combinations START = time.time() SIZE = 10**8 pfactor = pfactor_gen(SIZE) primes = [2, 3, 5, 7, 11, 13, 17, 19] def factor(n): return factor_given_pfactor(n, pfactor) def mapToFactorPow(n): factors = factor(n) powCounts = [factors.count(x) for x in set(factors)] return tuple(sorted(powCounts)[::-1]) def getMaxOptions(distro): lettersMerged = string.join([str(i) * num for i, num in enumerate(distro)], '') return len(set( combinations( \ lettersMerged, \ len(lettersMerged)/2 ))) gmo = getMaxOptions possible = dict()
#NOTE TODO need to solve it import time from primes import pfactor_gen, factor_given_pfactor, get_divisors_given_pfactor START = time.time() SIZE = 10**6 pfactor = pfactor_gen(SIZE) def factor(n): return factor_given_pfactor(n, pfactor) def get_divisors(n): return get_divisors_given_pfactor(n, pfactor) # This function is currently very slow for numbers with lots of factors =/ def practical_check(n): divs = get_divisors(n) div_sums = set([0]) for val in divs: div_sums.update(set([ val + num for num in div_sums])) div_sums = sorted(div_sums)[:n+1] print "On item:", n, "Time up to now:", time.time() - START return div_sums == range(n+1) pc = practical_check items = [] for i in xrange(21,SIZE-18,2): if pfactor[i] == i and pfactor[i+6] == i+6 and \ pfactor[i+12] == i+12 and pfactor[i+18] == i+18:
import time, math from primes import get_primes, factor_given_pfactor, pfactor_gen, get_divisors_given_pfactor START = time.time() SIZE = 10**8 primesList = get_primes(SIZE) pfactorList = pfactor_gen(SIZE) primeSet = set(primesList) def factor(n): return factor_given_pfactor(n, pfactorList) def divisors(n): return get_divisors_given_pfactor(n, pfactorList) answers = set() for p in primesList: print p divs = divisors(p + 1) for div1 in divs: for div2 in divs: if div1 <= div2: continue top = ((p + 1) * div1) / div2 - 1 bottom = ((p + 1) * div2) / div1 - 1 if top > SIZE: continue if top in primeSet and bottom in primeSet:
START = time.time() SIZE = 10**6 def get_divisors(n): # returns all divisors of n. return get_divisors_given_pfactor(n, pfactors) def factor(n): return sorted(factor_given_pfactor(n, pfactors)) def rep_dig_prime(p): potential_pows = get_divisors(p-1) for powz in potential_pows: if pow(10,powz,p) == 1: return powz pfactors = pfactor_gen(SIZE) values = [0] * SIZE values[3] = 1 for i in xrange(5,SIZE,2): #Evens are easy to compute, do it later if i %1024 == 1: print i if i %5 == 0: # multiples of 5 add no extra digits from the factor of 5. values[i] = values[i/5] continue if pfactors[i] == i: values[i] = rep_dig_prime(i) else: prime_factors = factor(i) values[i] = 1 for (index,prime) in enumerate(prime_factors): if prime == 3 and index == 1:
import time, math from primes import get_primes, factor_given_pfactor, pfactor_gen, get_divisors_given_pfactor START = time.time() SIZE = 10**8 primesList = get_primes(SIZE) pfactorList = pfactor_gen(SIZE) primeSet = set(primesList) def factor(n): return factor_given_pfactor(n, pfactorList) def divisors(n): return get_divisors_given_pfactor(n, pfactorList) answers = set() for p in primesList: print p divs = divisors(p+1) for div1 in divs: for div2 in divs: if div1 <= div2: continue top = ((p+1) * div1) / div2 - 1 bottom = ((p+1) * div2) / div1 - 1 if top > SIZE: continue if top in primeSet and bottom in primeSet: answers.add((top, p, bottom)) print sum([x[0] +x[1] + x[2] for x in answers])