Created
January 30, 2017 11:25
-
-
Save toanant/0c4063f5506a48b71ecf357b8bf46d42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
def is_prime(n): | |
if (n == 2) or (n == 3): | |
return True | |
if (n < 2) or (n %2 == 0): | |
return False | |
if n < 9: | |
return True | |
if n % 3 == 0: | |
return False | |
sqrt_n = int(n ** 0.5) | |
step = 5 | |
while step <= sqrt_n: | |
if n % step == 0: | |
return False | |
if n % (step + 2) == 0: | |
return False | |
step += 6 | |
return True | |
def is_circular_prime(n): | |
num = str(n) | |
for i in range(len(num)): | |
if not is_prime(int(num[i:] + num[:i])): | |
return False | |
return True | |
if __name__ == '__main__': | |
num = int(input()) | |
result = (sum(1 for n in range(2, num) if is_circular_prime(n))) | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment