103 Example

a guest
Nov 21st, 2020 (edited)
119
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. pi = ''
2.
3. with open('/path/to/pi.txt') as the_file: pi = the_file.read()      # This file should start without "3." in the front
4.
5. #-----------------------------------------------------------------------
6.
7. def prime_list(n):
8.     sieve = [True] * n
9.     for i in xrange(3, int(n ** 0.5) + 1, 2):
10.         if sieve[i]:
11.             sieve[i * i::2 * i]=[False]*((n - i * i - 1) / (2 * i) + 1)
12.     return [2] + [i for i in xrange(3, n, 2) if sieve[i]]
13.
14. print('Generating 100,000 prime numbers...\n')
15.
16. biggest_prime = 1299721 # The 100,001st prime
17. list_of_primes = prime_list(biggest_prime)
18.
19. #-----------------------------------------------------------------------
20.
21. for i in range(1, 21000):
22.     nth_prime = list_of_primes[i - 1]
23.     s = str(nth_prime)
24.
25.     digits = pi.split(s)[0] + s
26.     end_of = len(digits)
27.
28.     digits2 = pi[:nth_prime]
29.     digit_sum = 0
30.
31.     for digit in digits2:
32.         digit_sum += int(digit)
33.
34.     if str(end_of).endswith(str(digit_sum)) or str(digit_sum).endswith(str(end_of)):
35.         print('Prime #' + str(i) + ' is ' + s)
36.
37.         print(s + ' first appears in Pi at the end of ' + str(end_of) + ' digits')
38.         print(s + ' digits of Pi sum to ' + str(digit_sum) + '\n')
39.
40. # Pi:   53, 103, 1693, 4159, 5923, 75533
41. # Phi:  3, 281, 203183
42. # e:    3547, 15401
RAW Paste Data