Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-rosetta/blob/main/tasks/cuban-primes/oracle.py # omega-rosetta aien-dev/omega-rosetta Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-rosetta / tasks / cuban-primes / oracle.py` 33 lines ยท 944 bytes Raw Blame History 1 # Independent reference for "Cuban primes" (Python 3, standard library only). 2 # expected.txt is this program's stdout; omc never produced it. 3 def is_prime(n): 4 if n < 2: 5 return False 6 for p in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37): 7 if n % p == 0: 8 return n == p 9 d, s = n - 1, 0 10 while d % 2 == 0: 11 d //= 2 12 s += 1 13 for a in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37): 14 x = pow(a, d, n) 15 if x in (1, n - 1): 16 continue 17 for _ in range(s - 1): 18 x = x * x % n 19 if x == n - 1: 20 break 21 else: 22 return False 23 return True 24 cub, n = [], 0 25 while len(cub) < 100000: 26 n += 1 27 v = (n + 1) ** 3 - n ** 3 28 if is_prime(v): 29 cub.append(v) 30 print("first 200 cuban primes:") 31 for i in range(0, 200, 10): 32 print(" ".join(map(str, cub[i:i + 10]))) 33 print(f"the 100000th cuban prime: {cub[-1]}")