Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def isPrime(p):
- if primes[len(primes) - 1] ** 2 < p:
- print("Error: Attempted to prime check a number with an improper prime list!")
- return False
- for q in primes:
- if q**2 > p:
- return True
- if not p % q:
- return False
- def checkRotations(p):
- s = str(p)
- rotations = len(s) - 1
- for r in range(rotations):
- s += s[0]
- s = s[1:]
- if not isPrime(int(s)):
- return False
- return True
- primes = [2]
- p = 3
- n = 1
- show = False
- try:
- ceiling = int(input("Enter an upper bound for searching for primes: "))
- except ValueError:
- print("Error: Not a natural number!")
- exit()
- if str(input("Enable individual printout? [Y/n]: ")).upper() == "Y":
- show = True
- if show:
- print(primes[0], end = "\t")
- while p < ceiling:
- if isPrime(p):
- primes.append(p)
- n += 1
- if show:
- print(str(p), end = "\t")
- if not n % 10:
- print()
- p += 2
- print("\n" + str(len(primes)) + " primes found overall.")
- c = 0
- for p in primes:
- if checkRotations(p):
- if show:
- print(p, "is a circular prime.")
- c += 1
- print(c, "circular primes found overall.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement