def test_prime_count(self): self.assertEqual(pyprimes.prime_count(PRIMES[-1]), len(PRIMES)) # Table of values from http://oeis.org/A000720 # plus one extra 0 to adjust for Python's 0-based indexing. expected = [ 0, 0, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 17, 17, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 21, 21, 21, 21, 21, 21] for i, count in enumerate(expected): self.assertEqual(pyprimes.prime_count(i), count)
def test_prime_count(self): self.assertEqual(pyprimes.prime_count(PRIMES[-1]), len(PRIMES)) # Table of values from http://oeis.org/A000720 # plus one extra 0 to adjust for Python's 0-based indexing. expected = [ 0, 0, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 17, 17, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 21, 21, 21, 21, 21, 21 ] for i, count in enumerate(expected): self.assertEqual(pyprimes.prime_count(i), count)
def test_bertelsen(self): # http://mathworld.wolfram.com/BertelsensNumber.html result = pyprimes.prime_count(10**9) self.assertNotEqual( result, 50847478, "prime_count returns the erronous Bertelsen's Number") self.assertEqual(result, 50847534)
def test_prime_count_tens(self): # Test prime_count function with powers of ten. # Values come from: # http://mathworld.wolfram.com/PrimeCountingFunction.html # http://oeis.org/A006880 expected = [0, 4, 25, 168, 1229, 9592, 78498] for i, count in enumerate(expected): self.assertEqual(pyprimes.prime_count(10**i), count)
def test_prime_count_tens_big(self): # See also PyPrimesTest.test_prime_count_tens. self.assertEqual(pyprimes.prime_count(10**7), 664579) self.assertEqual(pyprimes.prime_count(10**8), 5761455)
def test_bertelsen(self): # http://mathworld.wolfram.com/BertelsensNumber.html result = pyprimes.prime_count(10**9) self.assertNotEqual(result, 50847478, "prime_count returns the erronous Bertelsen's Number") self.assertEqual(result, 50847534)
import pyprimes import itertools import math import time start = time.time() numList = [] below = 5000000 cUpper = math.ceil(below**(4**-1)) primeList = list(pyprimes.primes(2, math.ceil(math.sqrt(50000000)))) cList = primeList[:pyprimes.prime_count(cUpper - 1)] for i in range(len(cList) - 1, -1, -1): csquare = cList[i]**4 bUpper = math.ceil((below - csquare)**(3**-1)) bList = primeList[:pyprimes.prime_count(bUpper - 1)] for j in range(len(bList) - 1, -1, -1): bsquare = bList[j]**3 aUpper = math.ceil(math.sqrt(below - csquare - bsquare)) aList = primeList[:pyprimes.prime_count(aUpper - 1)] for k in range(len(aList) - 1, -1, -1): result = (aList[k]**2 + bsquare + csquare) if result not in numList: numList.append(result) print(len(numList))