-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathget_circular_prime_count
More file actions
50 lines (48 loc) · 1.4 KB
/
get_circular_prime_count
File metadata and controls
50 lines (48 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#PF-Assgn-57
import math
def check_prime(number):
#remove pass and write your logic here. if the number is prime return true, else return false
#number_sqrt = math.floor( math.sqrt(number))
number_sqrt = number//2
for i in range(2,number_sqrt):
if not(number%i):
return False
return True
def number_of_digits(num):
count=0
while(num):
count+=1
num=num//10
return count
def rotations(num):
digits = number_of_digits(num)
#print(digits)
round_number = []
round_number.append(num)
temp = num
while(1):
r = temp//math.pow(10,digits-1)
temp = int((temp%math.pow(10, digits-1))*10+r)
#print(temp)
if(temp == num):
break
round_number.append(temp)
#print(round_number)
return round_number
#rotations(179)
def get_circular_prime_count(limit):
#remove pass and write your logic here.It should return the count of circular prime numbers below the given limit.
count_prime=0
for i in range(2, limit):
round_num = rotations(i)
count=0
for j in round_num:
if check_prime(j):
count+=1
if count == len(round_num):
count_prime+=1
#print(count_prime)
return count_prime-1
#Provide different values for limit and test your program
#print(check_prime(12))
print(get_circular_prime_count(100))