def problem3(num): """ Largest prime factor. >>> problem3(13195) 29 >>> problem3(600851475143) 6857 """ primes_dict = lib.prime_factors(num) primes = primes_dict.keys() primes.sort() return primes[-1]
def problem12(n): """ return first triangle number to have over n divisors. where triangle number is the sum of first natural numbers. >>> problem12(500) 76576500 >>> problem12(5) 28 """ divisors, count = 1, 1 while divisors < n: count += 1 triangle = lib.sum_frist_N_numbers(count) primes_dict = lib.prime_factors(triangle) divisors = lib.product(map(lib.increment, primes_dict.values())) return triangle
# -*- coding: utf-8 -*- """ Created on Thu Jul 21 06:37:11 2016 @author: robbie """ import lib reload(lib) n = 600851475143 #n = 10086647L print(lib.prime_factors(n,999999))
from lib import prime_factors def multiples(n): for i in xrange(1, (n/2)): if n % i == 0: yield i if __name__ == '__main__': print(max(prime_factors(600851475143)))
from lib import prime_factors def multiples(n): for i in xrange(1, (n / 2)): if n % i == 0: yield i if __name__ == '__main__': print(max(prime_factors(600851475143)))
#!/usr/bin/env python3 import lib from collections import Counter # The prime factors of each number 1 to 20 counts = ([Counter(lib.prime_factors(i)) for i in range(2, 21)]) total = Counter() # Get the max count of each factor for count in counts: for n in count: if total[n] < count[n]: total[n] = count[n] res = lib.multiply([n**total[n] for n in total.keys()]) print(res)
#!/usr/bin/env python3 import lib from collections import Counter N = 1000000 D = 4 for i in range(N): pfactors = set() ok = True j = 0 while j < D and ok: f = Counter(lib.prime_factors(i + j)) if len(f.keys()) != D: ok = False if ok: pfactors.update(f.items()) j += 1 if ok and len(pfactors) == D * D: print(i) break
#!/usr/bin/env python3 import lib N = 600851475143 print(max(lib.prime_factors(N)))