def solve(): smallest_factor = Factors.smallestFactorOf(problemNumber) largest_factor = int(problemNumber/smallest_factor) for i in range(smallest_factor, largest_factor): if Factors.isFactor(problemNumber, i): counterpart = int(problemNumber/i) if Primes.is_prime(counterpart): return counterpart
def solve(): smallest_factor = Factors.smallestFactorOf(problemNumber) largest_factor = int(problemNumber / smallest_factor) for i in range(smallest_factor, largest_factor): if Factors.isFactor(problemNumber, i): counterpart = int(problemNumber / i) if Primes.is_prime(counterpart): return counterpart
#Find the sum of all the primes below two million. from modules import Primes problem_number = 2000000 primes = Primes.prime_numbers_below(problem_number) prime_sum = sum(primes) print(primes) print(prime_sum)
def test_isPrimeShouldReturnFalse(self): self.assertEqual(Primes.is_prime(9), False)
def test_isPrimeShouldReturnTrue(self): self.assertEqual(Primes.is_prime(23), True)
def test_prime_numbers_below_10(self): primes = Primes.prime_numbers_below(10) self.assertListEqual(primes, [2, 3, 5, 7])
def test_nth_prime_number_2nd(self): self.assertEqual(Primes.nth_prime_number(2), 3)
def test_nth_prime_number_6th(self): self.assertEqual(Primes.nth_prime_number(6), 13)
#What is the 10 001st prime number? from modules import Primes print(Primes.nth_prime_number(10001))