Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- # Use this code if you wish to generate Pi rather than opening it through a file
- # You will need mpmath to do this
- # pip install mpmath
- try:
- from sympy.mpmath import mp
- except ImportError:
- from mpmath import mp
- print('Generating 99,999 digits of Pi...\n')
- pi = ''
- mp.dps = 100000
- pi = str(mp.pi)[2:][:-3] + '541' # Remove 2 characters '3.' from the front and remove 3 incorrect digits from the end
- """
- pi = ''
- with open('/path/to/pi_file.txt') as the_file: pi = the_file.read() # This file must start with 14159 and not have the "3." in the front
- #-----------------------------------------------------------------------
- def prime_list(n):
- sieve = [True] * n
- for i in xrange(3, int(n ** 0.5) + 1, 2):
- if sieve[i]:
- sieve[i * i::2 * i]=[False]*((n - i * i - 1) / (2 * i) + 1)
- return [2] + [i for i in xrange(3, n, 2) if sieve[i]]
- print('Generating 100,000 prime numbers...\n')
- biggest_prime = 1299721 # The 100,001st prime
- list_of_primes = prime_list(biggest_prime)
- #-----------------------------------------------------------------------
- for i in range(1, 15000):
- print(i)
- nth_prime = list_of_primes[i - 1]
- twice_nth_prime = nth_prime * 2
- s = str(twice_nth_prime)
- digits = pi.split(s)[0] + s
- end_of = len(digits)
- digit_sum = 0
- for digit in digits:
- digit_sum += int(digit)
- if digit_sum % nth_prime == 0:
- print(twice_nth_prime)
- raw_input('We have a winner!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement