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.txt') as the_file: pi = the_file.read() # This file should start without "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 = 1299709 # Prime #100000
- list_of_primes = prime_list(biggest_prime)
- #-----------------------------------------------------------------------
- for i in range(1, 100000):
- nth_prime = list_of_primes[i - 1]
- doubled = i * 2
- s = str(nth_prime)
- digits = pi.split(s)[0] + s
- end_of = len(digits)
- if doubled == end_of:
- print(str(nth_prime) + ' is prime #' + str(i))
- print(str(nth_prime) + ' first appears in Pi at the end of ' + str(end_of) + ' digits\n')
- """
- Pi
- 71 (prime #20) first appears in Pi at the end of 40 digits
- 359 (prime #72) first appears in Pi at the end of 144 digits
- Phi
- 43 (prime #14) first appears in Phi at the end of 28 digits
- e
- 85781 (prime #8346) first appears in e at the end of 16692 digits
- 2Pi
- 5 (prime #3) first appears in 2Pi at the end of 6 digits
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement