def radical(n): """Calculates the radical, the product of the unique prime factors of the given integer""" return reduce(op.mul, get_prime_factors(n).keys(), 1)
def test_solution(self): self.assertEqual(6857, euler.get_prime_factors(600851475143)[-1])
#!/usr/bin/env python """ Problem 003: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 317584931803? """ from euler import get_prime_factors N = 600851475143 print(max(get_prime_factors(N).keys()))
# coding=utf-8 ''' Problem 47 04 July 2003 The first two consecutive numbers to have two distinct prime factors are: 14 = 2 × 7 15 = 3 × 5 The first three consecutive numbers to have three distinct prime factors are: 644 = 2² × 7 × 23 645 = 3 × 5 × 43 646 = 2 × 17 × 19. Find the first four consecutive integers to have four distinct primes factors. What is the first of these numbers? ''' import euler factors = dict.fromkeys([1], 0) for i in range(10**6): factors[i] = len(set(euler.get_prime_factors(i))) if (factors[i] == 4) and (factors[i-1] == 4) and (factors[i-2] == 4) and (factors[i-3] == 4): print i -3 break
# coding=utf-8 ''' Problem 47 04 July 2003 The first two consecutive numbers to have two distinct prime factors are: 14 = 2 × 7 15 = 3 × 5 The first three consecutive numbers to have three distinct prime factors are: 644 = 2² × 7 × 23 645 = 3 × 5 × 43 646 = 2 × 17 × 19. Find the first four consecutive integers to have four distinct primes factors. What is the first of these numbers? ''' import euler factors = dict.fromkeys([1], 0) for i in range(10**6): factors[i] = len(set(euler.get_prime_factors(i))) if (factors[i] == 4) and (factors[i - 1] == 4) and (factors[i - 2] == 4) and (factors[i - 3] == 4): print i - 3 break
#!/usr/bin/env python """ Problem 005: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest number that is evenly divisible by all of the numbers from 1 to 20? """ from euler import get_prime_factors, op, reduce N = 20 factors = {} for n in range(1, N + 1): for k, v in get_prime_factors(n).items(): if k in factors: if v > factors[k]: factors[k] = v else: factors[k] = v print(reduce(op.mul, [k**v for k, v in factors.items()], 1))