Advertisement
AceScottie

google_prime_id.py

Jan 17th, 2023
1,450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | Source Code | 0 0
  1. def factiorials(max_n):
  2.     f = [0]
  3.     x = 1
  4.     for i in range(1, max_n+1):
  5.         x *= i
  6.         f.append(x)
  7.     return f
  8. def isPrime(j, f):
  9.     return (f[j-1]+1)%j == 0
  10. def solution(n):
  11.     max_int= int((n+5)*(5000/2465)+475)
  12.     facts = factiorials(max_int)
  13.     id_str = ''.join([str(x) for x in range(2, max_int+1) if isPrime(x, facts)])
  14.     return id_str[n:n+5]
  15.  
  16. from time import perf_counter
  17. start = perf_counter()
  18. for i in range(10000):
  19.     s = perf_counter()
  20.     print(i, solution(i), f"completed in: {perf_counter()-s}s")
  21. print(f"elapsed {perf_counter()-start}")
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement