A prime number is a Circular Prime Number if all of its possible rotations are itself prime numbers. Now given a number N check if it is Circular Prime or Not.
 
Example 1:
Input: N = 197
Output: 1
Explanation: 197 is a Circular Prime because
all rotations of 197 are 197, 719, 971 all of 
the 3 are prime number's hence 197 is a 
circular prime.
Example 2:
Input: N = 101
Output: 0
Explanation: 101 and 11 is prime but 110 is
not a prime number.
 
Your Task:
You don't need to read or print anything. Your task is to complete the function isCircularPrime() which takes N as input parameter and returns 1 if it is Circular Prime otherwise returns 0.
 
Expected Time Complexity: O(Nlog(log(N))
Expected Space Complexity: O(N)
 
Constraints:
1 <= N <= 10^{5}

Difficulty: EASY
Tags: Number theory

Mathematics
Expected Time Complexity: O(Nlog(log(N))
Expected Auxiliary Space: O(N)

Starter code:
#User function Template for python3

class Solution:
	def isCircularPrime(self, n):
		# Code here

Solutions:
class Solution:

	def isCircularPrime(self, n):

		def isprime(x):
			if x == 1:
				return False
			for i in range(2, int(x ** 0.5) + 1):
				if x % i == 0:
					return False
			return True
		n = str(n)
		for i in range(1, len(n) + 1):
			c = n[i:] + n[:i]
			c = int(c)
			if not isprime(c):
				return 0
		return 1


class Solution:

	def isCircularPrime(self, n):
		if n == 1:
			return 0
		l = len(str(n))
		x = l
		while l > 0:
			for i in range(2, n // 2 + 1):
				if n % i == 0:
					return 0
			temp = str(n)
			n = int(temp[x - 1:] + temp[:x - 1])
			l -= 1
		return 1


class Solution:

	def isCircularPrime(self, n):

		def p(n):
			if n == 0 or n == 1:
				return False
			s = int(n ** 0.5)
			for i in range(2, s + 1):
				if n % i == 0:
					return False
			return True
		l = len(str(n))
		e = list(str(n))
		c = 0
		for i in range(l):
			if p(int(''.join(e))):
				c += 1
			e.insert(0, e[-1])
			e.pop()
		if c == l:
			return 1
		return 0


class Solution:

	def isCircularPrime(self, n):
		if n == 1:
			return 0
		size = len(str(n))
		t = size
		while size > 0:
			for i in range(2, n // 2 + 1):
				if n % i == 0:
					return 0
			temp = str(n)
			n = int(temp[t - 1:] + temp[:t - 1])
			size -= 1
		return 1


class Solution:

	def iscomposite(self, n):
		if n == 1:
			return True
		k = int(n ** 0.5)
		for i in range(2, k + 1):
			if n % i == 0:
				return True
		return False

	def isCircularPrime(self, n):
		g = str(n)
		N = len(g)
		for i in range(N):
			g = g[1:] + g[:1]
			if self.iscomposite(int(g)):
				return 0
		return 1


class Solution:

	def isCircularPrime(self, n):
		rotable_int = str(n)
		for i in range(n):
			rotable_int = rotable_int[1:] + rotable_int[0]
			checkable_int = int(rotable_int)
			if not self.is_prime(checkable_int):
				return 0
		return 1

	def is_prime(self, num):
		if num < 2:
			return False
		i = 2
		while i * i <= num:
			if num % i == 0:
				return False
			i += 1
		return True


class Solution:

	def isCircularPrime(self, n):
		if n == 1:
			return 0
		size = len(str(n))
		l = size
		while size:
			for i in range(2, n // 2 + 1):
				if n % i == 0:
					return 0
			temp = str(n)
			n = int(temp[l - 1] + temp[:l - 1])
			size -= 1
		return 1
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		n = int(input())
		ob = Solution()
		ans = ob.isCircularPrime(n)
		print(ans)


class Solution:

	def isCircularPrime(self, n):

		def sieve(n):
			dummy = [True for i in range(n + 1)]
			dummy[0] = dummy[1] = False
			i = 2
			while i * i <= n:
				for j in range(i * i, n + 1, i):
					dummy[j] = False
				i += 1
			return dummy
		listNum = []
		n = str(n)
		for i in range(len(n)):
			n = n[1:] + n[0]
			listNum.append(int(n))
		sieveList = sieve(max(listNum))
		for i in listNum:
			if sieveList[i] == False:
				return 0
		return 1


class Solution:

	def isPrime(self, num):
		if num > 1:
			for i in range(2, num):
				if num % i == 0:
					return False
			else:
				return True
		return False

	def isCircularPrime(self, n):
		if n == 1:
			return 0
		s1 = str(n)
		lst1 = []
		lst2 = [0] * len(s1)
		for i in s1:
			lst1.append(i)
		for i in range(len(lst1)):
			s2 = ''
			for j in range(i, len(lst1)):
				s2 += lst1[j]
			for k in range(i):
				s2 += lst1[k]
			lst2[i] = s2
		flag = False
		for i in lst2:
			if self.isPrime(int(i)):
				flag = True
			else:
				flag = False
				break
		if flag:
			return 1
		else:
			return 0


import math as mat

def convert(l):
	ans = 0
	for i in l:
		ans = ans * 10 + i
	return ans

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	for i in range(2, int(mat.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

class Solution:

	def isCircularPrime(self, n):
		l = []
		count = 0
		while n > 0:
			l.append(n % 10)
			n = int(n / 10)
			count = count + 1
		i = 0
		l.reverse()
		while i < count:
			flag = l[0]
			l.remove(flag)
			l.append(flag)
			if isPrime(convert(l)) == False:
				return 0
			else:
				i = i + 1
		return 1


def convert(l):
	ans = 0
	for i in l:
		ans = ans * 10 + i
	return ans

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

class Solution:

	def isCircularPrime(self, n):
		l = []
		count = 0
		while n > 0:
			l.append(n % 10)
			n = int(n / 10)
			count = count + 1
		i = 0
		l.reverse()
		while i < count and isPrime(convert(l)):
			flag = l[0]
			l.remove(flag)
			l.append(flag)
			i = i + 1
		if i == count:
			return 1
		else:
			return 0


class Solution:

	def isCircularPrime(self, n):
		c = len(str(n))
		e = int(n)
		count = 0
		s = e
		if e == 1:
			return 0
		else:
			for j in range(0, c):
				f = s % 10
				a = s // 10
				b = f * 10 ** (c - 1)
				s = b + a
				m = s // 2
				i = 2
				while i <= m:
					if s % i == 0:
						return 0
						break
					else:
						i += 1
				if i > m:
					count += 1
			if count == c:
				return 1
			else:
				return 0


import math

class Solution:

	def isPrime(self, n):
		if n == 2:
			return 1
		if n == 1:
			return 0
		for i in range(2, math.floor(math.sqrt(n)) + 1):
			if n % i == 0:
				return 0
		return 1

	def isCircularPrime(self, n):
		x = str(n)
		if len(x) == 1:
			if self.isPrime(int(x)) == 0:
				return 0
			else:
				return 1
		for i in range(len(x)):
			y = str(x[i + 1:] + x[:i + 1])
			if self.isPrime(int(y)) == 0:
				return 0
		return 1


class Solution:

	def isCircularPrime(self, n):
		if n == 1:
			return '0'
		else:
			x = str(n)
			y = x + x
			li = list()
			a = 0
			b = len(x)
			for i in range(len(x)):
				c = ''
				for i in range(a, b):
					c += str(y[i])
				d = c.lstrip('0')
				li.append(int(d))
				a += 1
				b += 1
			c = 0
			for i in li:
				for j in range(2, i):
					if i % j == 0:
						c += 1
			if c == 0:
				return '1'
			else:
				return '0'


class Solution:

	def prime(self, n):
		if n == 1:
			return 0
		for i in range(2, n // 2 + 1):
			if n % i == 0:
				return 0
		return 1

	def isCircularPrime(self, n):
		s = str(n)
		for i in range(len(s)):
			if not self.prime(int(s)):
				return 0
			s = s[1:] + s[0]
		return 1


class Solution:

	def isCircularPrime(self, n):
		if n <= 1:
			return 0
		else:
			s = str(n)
			nl = list(s)
			temp = s[0]
			l = len(s)
			c = l
			li = [s]
			while c > 1:
				nl.insert(0, nl[l - 1])
				del nl[l]
				li.append(''.join(nl))
				c -= 1
			nl = []
			prime = True
			for n in li:
				if n == 2:
					prime = True
				else:
					for i in range(2, int(n)):
						if int(n) % i == 0:
							prime = False
							break
					if prime:
						nl.append(int(n))
					prime = True
			if len(li) == len(nl):
				return 1
			else:
				return 0


class Solution:

	def isCircularPrime(self, n):
		n = str(n)
		lst = list(n)
		circular = []
		for i in range(len(lst)):
			last = lst.pop()
			circular.append(last + ''.join(lst))
			lst = [last] + lst

		def isprime(num):
			if num > 1:
				for i in range(2, num):
					if num % i == 0:
						return False
			else:
				return False
			return True
		count = 0
		for i in range(len(circular)):
			if isprime(int(circular[i])):
				count += 1
		if count == len(circular):
			return 1
		else:
			return 0


class Solution:

	def isCircularPrime(self, n):
		k = str(n)

		def isPrime(a):
			if a == 2 or a == 3:
				return True
			if a == 1 or a % 2 == 0 or a % 3 == 0:
				return False
			elif a % 6 == 1 or a % 6 == 5:
				t = 5
				while t < a:
					if a % t == 0 and t != a:
						return False
					t += 2
					if a % t == 0 and t != a:
						return False
					t += 4
			return True
		if len(k) == 1:
			if isPrime(n):
				return 1
			return 0
		for i in range(len(k)):
			temp_str = k[i:] + k[:i]
			if not isPrime(int(temp_str)):
				return 0
		return 1


class Solution:

	def isCircularPrime(self, n):
		if n == 1 or n == 10:
			return 0
		else:
			a = str(n)
			l = 0
			b = []
			for i in range(len(a)):
				l += 1
				x = a[l:len(a)] + a[0:l]
				b.append(x)
			y = []
			for i in range(len(b)):
				t = int(b[i])
				y.append(t)
			c = 0
			for i in range(len(y)):
				if y[i] > 0:
					for j in range(2, y[i]):
						if y[i] % j == 0:
							return 0
							break
					else:
						c += 1
						if c == len(y):
							return 1


class Solution:

	def isCircularPrime(self, n):
		a = str(n)
		b = list(a)
		c = []
		if len(b) == 1 and int(b[0]) <= 1:
			return 0
		elif len(b) == 1:
			c.append(int(b[0]))
		for i in range(len(b)):
			c.append(int(''.join(b)))
			e = b.pop()
			b.insert(0, e)
		for i in c:
			for j in range(2, i):
				if i % j == 0:
					return 0
					break
		else:
			return 1


from math import sqrt

class Solution:

	def isPrime(self, j):
		for i in range(2, int(sqrt(j)) + 1):
			if j % i == 0:
				return False
		else:
			return True

	def isCircularPrime(self, n):
		if n == 1:
			return '0'
		n = str(n)
		for i in range(len(n)):
			k = n[1:len(n)] + n[0]
			j = int(k)
			if self.isPrime(j) == False:
				return '0'
			n = k
		return '1'


class Solution:

	def get_permutation(self, string, i, arr):
		arr1 = list(string)
		for i in range(len(string)):
			arr.append(''.join(arr1))
			p1 = arr1.pop(0)
			arr1.append(p1)

	def isCircularPrime(self, n):
		if n == 1:
			return 0
		n2 = 100000
		prime = [True for i in range(n2 + 1)]
		i = 2
		while i * i <= n2:
			if prime[i]:
				for j in range(i * i, n2 + 1, i):
					prime[j] = False
			i += 1
		arr = []
		self.get_permutation(str(n), 0, arr)
		for d in arr:
			if not prime[int(d)]:
				return 0
		return 1


import math

class Solution:

	def isCircularPrime(self, n):

		def prime(n):
			dp = [1] * (n + 1)
			(dp[0], dp[1]) = (0, 0)
			for i in range(2, int(math.sqrt(n)) + 1):
				if dp[i]:
					for j in range(2 * i, n + 1, i):
						dp[j] = 0
			return dp[n]
		n = str(n)
		t = len(n)
		while t:
			n = n[1:] + n[0]
			if not prime(int(n)):
				return 0
			t -= 1
		return 1


prime = [True] * 1000000
for i in range(4, 1000000, 2):
	prime[i] = False
for i in range(3, 1000000, 2):
	if prime[i]:
		for j in range(i * i, 1000000, i):
			prime[j] = False
prime[0] = False
prime[1] = False

class Solution:

	def isCircularPrime(self, n):
		if not prime[n]:
			return 0
		s = str(n)
		for i in range(len(s)):
			s = s[-1] + s[:-1]
			if not prime[int(s)]:
				return 0
		return 1


import math

class Solution:

	def isCircularPrime(self, n):
		if n == 1:
			return 0
		s = len(str(n))
		t = s
		while s > 0:
			for i in range(2, n // 2 + 1):
				if n % i == 0:
					return 0
			temp = str(n)
			n = int(temp[t - 1:] + temp[:t - 1])
			s -= 1
		return 1


import math

class Solution:

	def check(self, s):
		c = 0
		for i in range(2, int(math.sqrt(s)) + 1):
			if s % i == 0:
				return 0
		return 1

	def isCircularPrime(self, n):
		s = str(n)
		s = list(s)
		if n == 1:
			return 0
		elif len(set(s)) == 1:
			if ob.check(int(n)):
				return 1
			else:
				return 0
		elif ob.check(n):
			f = 0
			for i in range(0, len(str(n)) - 1):
				n = str(n)
				k = n[0]
				n += k
				n = n[1:]
				if ob.check(int(n)):
					f = 1
				else:
					f = 0
					break
			if f == 1:
				return 1
			else:
				return 0
		else:
			return 0


import math

class Solution:

	def isPrime(self, num):
		if num < 2:
			return False
		if num == 2:
			return True
		for i in range(2, int(math.sqrt(num)) + 1):
			if num % i == 0:
				return False
		return True

	def isCircularPrime(self, n):
		numArr = list(str(n))
		for i in range(len(numArr)):
			numArr = numArr[1:] + numArr[:1]
			num = int(''.join(numArr))
			if not self.isPrime(num):
				return 0
		return 1


class Solution:

	def isCircularPrime(self, n):
		temp = str(n)
		l = len(temp)
		count = 0
		if len(temp) == 1:
			if n == 1 or n == 4 or n == 6 or (n == 8) or (n == 9):
				return 0
			if n == 2 or n == 3 or n == 5 or (n == 7):
				return 1
		for i in range(len(temp)):
			a = temp[i:l] + temp[:i]
			count1 = 0
			a = int(a)
			for i in range(2, a // 2 + 1):
				if a % i == 0:
					count1 += 1
			if count1 < 1:
				count += 1
		if count == len(temp):
			return 1
		return 0


class Solution:

	def circular(self, n):
		n = str(n)
		arr = []
		m = n[-1] + n[:-1]
		arr.append(m)
		while n != m:
			m = m[-1] + m[:-1]
			arr.append(m)
		return arr

	def prime(self, n):
		if n == 1:
			return False
		for i in range(2, n):
			if n % i == 0:
				return False
		return True

	def isCircularPrime(self, n):
		arr = self.circular(n)
		for i in arr:
			if not self.prime(int(i)):
				return 0
		return 1


class Solution:

	def isPrime(self, n):
		for x in range(2, n):
			if n % x == 0:
				return False
		return True

	def isCircularPrime(self, n):
		if n == 1:
			return 0
		l = str(n)
		m = 0
		k = 0
		while k < len(l):
			if not self.isPrime(int(l)):
				m = 1
				break
			l = l[1:] + l[0]
			k += 1
		if m:
			return 0
		return 1


import math

class Solution:

	def isCircularPrime(self, n):

		def isprime(num):
			for i in range(3, int(math.sqrt(num)) + 1, +2):
				if num % i == 0:
					return 0
			return 1
		if n == 1:
			return 0
		if n == 2:
			return 1
		temp = n
		no_of_dig = 0
		while temp:
			if temp % 2 == 0:
				return 0
			temp = temp // 10
			no_of_dig += 1
		for i in range(no_of_dig):
			f = isprime(n)
			if f == 0:
				return 0
			first_dig = n % 10 * pow(10, no_of_dig - 1)
			n = n // 10
			n = first_dig + n
		return 1


class Solution:

	def isprime(self, n):
		flag = 0
		n = int(n)
		if n == 0 or n == 1:
			return 0
		for i in range(2, n):
			if n % i == 0:
				flag = 1
				break
		if flag == 1:
			return 0
		else:
			return 1

	def isCircularPrime(self, n):
		n = str(n)
		l = len(n) - 1
		cnt = 0
		if self.isprime(n):
			cnt = 1
		while l > 0:
			val = int(n[l:] + n[0:l])
			if self.isprime(val):
				cnt += 1
			l -= 1
		if cnt == len(n):
			return 1
		return 0


from math import sqrt

class Solution:

	def cp(self, n):
		prime_flag = 0
		if n > 1:
			for i in range(2, int(sqrt(n)) + 1):
				if n % i == 0:
					prime_flag = 1
					break
			if prime_flag == 0:
				return 1
			else:
				return 0
		else:
			return 0

	def isCircularPrime(self, n):
		s = str(n)
		l1 = len(s)
		f = 1
		x = ''
		s1 = ''
		for i in range(len(s)):
			x = ''
			if i == 0:
				x = s
				if ob.cp(int(x)):
					pass
				else:
					f = 0
					break
				s1 = s1 + s[0]
			else:
				x = s[i:l1]
				x = x + s1
				if ob.cp(int(x)):
					pass
				else:
					f = 0
					break
				s1 = s1 + s[i]
		return f


import math

class Solution:

	def isCircularPrime(self, n):
		if n == 1:
			return 0
		nString = str(n)
		for i in range(0, len(nString)):
			num = self.modString(nString, i)
			if not self.isPrime(num):
				return 0
		return 1

	def modString(self, string, count):
		newString = ''
		for i in range(0, len(string)):
			newString += string[(i + count) % len(string)]
		return int(newString)

	def isPrime(self, n):
		if n > 1:
			for i in range(2, int(math.sqrt(n)) + 1):
				if n % i == 0:
					return False
			return True
		return True


class Solution:

	def isCircularPrime(self, n):
		t = n
		lst = [1, 4, 6, 8, 9, 10]
		if n in lst:
			return 0
		n = str(n)
		l = len(n)

		def rotate(n, l):
			res = ''
			res = res + n[l - 1]
			res = res + n[0:l - 1]
			return res

		def check_prime(num):
			cnt = 0
			for i in range(1, num + 1):
				if num % i == 0:
					cnt = cnt + 1
			if cnt == 2:
				return True
			else:
				return False
		if check_prime(t) == False:
			return 0
		for i in range(l - 1):
			x = rotate(n, l)
			x = int(x)
			flag = check_prime(x)
			if flag == False:
				return 0
			n = str(x)
		return 1


class Solution:

	def isCircularPrime(self, n):
		a = str(n)
		s = a + a
		l = 0
		for i in range(len(a)):
			p = int(s[i:i + len(a)])
			c = 0
			if p == 1:
				c = 1
			for i in range(2, p - 1):
				if p % i == 0:
					c = 1
					break
			if c == 0:
				l += 1
		if l == len(a):
			return 1
		else:
			return 0


class Solution:
	isPrime = []

	def isCircularPrime(self, n):
		m = len(str(n))
		x = str(n)
		for i in range(m):
			x = x[1:] + x[0]
			if not self.isPrime(int(x)):
				return 0
		return 1

	def isPrime(self, n):
		if n == 1:
			return 0
		if n == 2:
			return 1
		if n & 1 == 0:
			return 0
		for i in range(3, int(pow(n, 0.5)) + 1, 2):
			if n % i == 0:
				return 0
		return 1


class Solution:

	def isCircularPrime(self, n):
		num_str = list(str(n))
		return self.leftRotate(num_str, len(num_str), len(num_str))

	def leftRotate(self, arr, d, n):
		count = 0
		for i in range(d):
			count += self.leftRotatebyOne(arr, n)
		if count == len(arr):
			return 1
		return 0

	def leftRotatebyOne(self, arr, n):
		temp = arr[0]
		for i in range(n - 1):
			arr[i] = arr[i + 1]
		arr[n - 1] = temp
		num = int(''.join(arr))
		if self.PrimeChecker(num) == 1:
			return 1
		return 0

	def PrimeChecker(self, a):
		if a > 1:
			for j in range(2, int(a / 2) + 1):
				if a % j == 0:
					return 0
					break
			else:
				return 1
		else:
			return 0


import math

class Solution:

	def prime(self, n):
		if n <= 1:
			return False
		if n <= 3:
			return True
		if n % 2 == 0 or n % 3 == 0:
			return False
		i = 5
		while i * i <= n:
			if n % i == 0 or n % (i + 2) == 0:
				return False
			i += 6
		return True

	def isCircularPrime(self, n):
		count = 0
		num = n
		temp = n
		while temp > 0:
			count += 1
			temp //= 10
		while self.prime(num):
			rem = num % 10
			div = num // 10
			num = 10 ** (count - 1) * rem + div
			if num == n:
				return 1
		return 0


from math import *

class Solution:

	def isPrime(self, n):
		for i in range(2, int(sqrt(n)) + 1):
			if n % i == 0:
				return False
		return True

	def isCircularPrime(self, n):
		if n == 1:
			return 0
		s = [int(i) for i in str(n)]
		fg = 1
		for i in range(len(s)):
			k = s.pop(0)
			s.append(k)
			st = ''
			for i in s:
				st += str(i)
			n = int(st)
			if self.isPrime(n):
				continue
			else:
				fg = 0
				break
		return fg


class Solution:

	def prime(self, num):
		if num == 2:
			return True
		if num == 1:
			return False
		for i in range(2, int(num ** 0.5) + 1):
			if num % i == 0:
				return False
		return True

	def isCircularPrime(self, n):
		n = list(str(n))
		l = []
		for i in range(len(n)):
			n.append(n.pop(0))
			ans = self.prime(int(''.join(n)))
			if not ans:
				return 0
		return 1


class Solution:

	def __init__(self):
		self.max = 100000
		self.prime = [True] * self.max

	def sieve(self):
		self.prime[1] = False
		self.prime[0] = False
		i = 2
		while i * i < self.max:
			if self.prime[i] == False:
				i += 1
				continue
			for j in range(2 * i, self.max, i):
				self.prime[j] = False
			i += 1

	def isCircularPrime(self, n):
		self.sieve()
		d = 0
		i = n
		while i > 0:
			d += 1
			i //= 10
		j = n
		p = pow(10, d - 1)
		for _ in range(d):
			if self.prime[j] == False:
				return 0
			j = j % 10 * p + j // 10
		return 1


class Solution:

	def isCircularPrime(self, n):
		if n == 1:
			return 0

		def iss(a):
			if a <= 1:
				return True
			if a in [2, 3, 5]:
				return True
			if a % 2 == 0 or a % 3 == 0 or a % 5 == 0:
				return False
			i = 5
			while i * i <= a:
				if a % i == 0 or a % (i + 2) == 0:
					return False
				i = i + 2
			return True
		a = str(n)
		for i in range(len(a)):
			new = a[i:] + a[:i]
			if not iss(int(new)):
				return 0
		return 1


class Solution:

	def isCircularPrime(self, n):
		if int(n) == 1:
			return 0
		else:
			s = str(n)
			n1 = str(s)
			c = 0
			for i in range(len(n1)):
				s = n2 = s[1:] + n1[i]
				count = 0
				for j in range(2, int(n2)):
					if int(n2) % j == 0:
						count = 1
						break
				if count == 0:
					c += 1
		if c == len(n2):
			return 1
		else:
			return 0


class Solution:

	def isCircularPrime(self, n):
		if n == 1:
			return 0
		import math

		def func(n):
			if n < 20:
				count = 0
			else:
				count = 1
			for i in range(1, 20):
				if n % i == 0:
					count += 1
			if count == 2:
				return True
			return False
		m = len(str(n))
		for i in range(m):
			if func(int(n)) == False:
				return 0
			temp = str(n)
			first = temp[0]
			second = temp[1:]
			n = second + first
		return 1


class Solution:

	def isPrime(self, n):
		self.n = n
		if n == 0 or n == 1:
			return 0
		else:
			flag = 0
			for i in range(2, n):
				if n % i == 0:
					flag = 1
					break
			if flag == 0:
				return 1
			else:
				return 0

	def isCircularPrime(self, n):
		self.n = n
		s = str(n)
		l = list(s)
		count = 0
		for i in range(0, len(l)):
			if i >= 1:
				t = l[len(s) - 1]
				l.pop(-1)
				l.insert(0, t)
				str1 = ''.join(l)
				if self.isPrime(int(str1)) == 1:
					count += 1
			elif self.isPrime(int(s)) == 1:
				count += 1
		if count == len(s):
			return 1
		else:
			return 0


import math

def isPrime(n):
	if n <= 1:
		return False
	if n == 2:
		return True
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

class Solution:

	def isCircularPrime(self, n):
		length = len(str(n))
		if length == 1:
			if isPrime(n):
				return 1
		copy = length
		copy2 = length
		multiplier = 1
		count = 0
		while copy != 1:
			multiplier *= 10
			copy = copy - 1
		while length != 0:
			last = n % 10
			n = n // 10
			appender = last * multiplier
			n = n + appender
			length = length - 1
			if isPrime(int(n)):
				count = count + 1
		if count == copy2:
			return 1
		else:
			return 0


def prime(n):
	if n == 2 or n == 3:
		return True
	if n % 2 == 0 or n == 1:
		return False
	for i in range(3, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True

class Solution:

	def isCircularPrime(self, n):
		n = str(n)
		for i in range(len(n)):
			temp = n[i:] + n[:i]
			if prime(int(temp)) == False:
				return 0
		return 1


class Solution:

	def isCircularPrime(self, n):
		max_num = n
		curr_num = 0
		num_to_check = []
		num_of_digits = 0
		num = n
		while num > 0:
			num_of_digits += 1
			num = int(num / 10)
		powTen = pow(10, num_of_digits - 1)
		while curr_num != n:
			if curr_num == 0:
				curr_num = n
			first_digit = int(curr_num / powTen)
			curr_num = curr_num * 10 + first_digit
			curr_num = curr_num - first_digit * powTen * 10
			num_to_check.append(curr_num)
			if max_num < curr_num:
				max_num = curr_num
		notPrime = {}
		notPrime[1] = True
		for i in range(2, max_num):
			if i in notPrime:
				continue
			for j in range(i * i, max_num + 1, i):
				notPrime[j] = True
		for num in num_to_check:
			if num in notPrime:
				return 0
		return 1


class Solution:

	def isCircularPrime(self, n):
		l = len(str(n))
		for i in range(l):
			temp = n % 10
			n = n // 10
			k = temp * 10 ** (l - 1) + n
			if not self.check(k):
				return 0
			n = k
		return 1

	def check(self, n):
		if n > 1:
			for i in range(2, int(n / 2) + 1):
				if n % i == 0:
					return False
					break
			else:
				return True
		else:
			return False


class Solution:

	def isPrime(self, num):
		for i in range(2, num // 2 + 1):
			if num % i == 0:
				return False
		return True

	def isCircularPrime(self, n):
		if n == 1:
			return 0
		size = num = len(str(n))
		while num > 0:
			if not self.isPrime(n):
				return 0
			n = int(str(n)[-1] + str(n)[:size - 1])
			num -= 1
		return 1


class Solution:

	def isCircularPrime(self, n):
		sn = str(n)
		for _ in range(len(sn)):
			if n is 1:
				return 0
			f = 2
			while f * f <= n:
				if n % f == 0:
					return 0
				f += 1
			sn = sn[1:] + sn[0]
			n = int(sn)
		return 1


class Solution:

	def isCircularPrime(self, n):
		if n == 1:
			return 0
		temp = str(n)
		nums = []
		l = len(temp)
		for _ in range(l):
			nums.append(int(temp))
			temp = temp[l - 1:] + temp[0:l - 1]
		m = max(nums)
		arr = [True] * (m + 1)
		i = 2
		while i * i <= m:
			if arr[i]:
				j = i * i
				while j <= m:
					if j % i == 0:
						arr[j] = False
					j += 1
			i += 1
		check = 1
		for t in nums:
			if arr[t] == False:
				check = 0
				break
		return check


class Solution:

	def isCircularPrime(self, n):
		if n < 2:
			return 0
		num_str = str(n)
		for i in range(0, len(num_str)):
			num_str = num_str[1:] + num_str[0:1]
			n_rot = int(num_str)
			for j in range(2, n_rot):
				if n_rot % j == 0:
					return 0
		return 1


import math

class Solution:

	def isPrime(self, num):
		if num == 1:
			return False
		if num == 2:
			return True
		if num % 2 == 0:
			return False
		for div in range(3, int(math.sqrt(num)) + 1, 2):
			if num % div == 0:
				return False
		return True

	def isCircularPrime(self, n):
		if n < 10:
			return 1 if self.isPrime(n) else 0
		numStr = str(n)
		for rotation in range(len(str(n))):
			num = int(numStr)
			if not self.isPrime(num):
				return 0
			(firstChar, rem) = (numStr[0], numStr[1:])
			numStr = rem + firstChar
		return 1


class Solution:

	def isCircularPrime(self, n):
		c = 0
		v = [n]
		ans = str(n)
		o = len(ans)
		for i in range(o - 1):
			ans = str(ans[1:]) + str(ans[0])
			v.append(int(ans))
		for j in v:
			if j > 1:
				for i in range(2, int(j / 2) + 1):
					if j % i == 0:
						return 0
				else:
					c = 1
			else:
				return 0
		return c


from collections import deque

class Solution:

	def isPrime(self, n):
		i = 2
		while i * i <= n:
			if n % i == 0:
				return 1
			i += 1
		return 0

	def isCircularPrime(self, n):
		if n == 1:
			return 0
		q = deque()
		for i in str(n):
			q.append(i)
			if self.isPrime(n):
				return 0
		l = len(q)
		while l - 1:
			q.appendleft(q.pop())
			temp = int(''.join(q))
			if self.isPrime(temp):
				return 0
			l -= 1
		return 1


from math import sqrt, ceil

class Solution:

	def isCircularPrime(self, num):

		def isPrime(n):
			if n == 0 or n == 1:
				return False
			if n == 2:
				return True
			t = ceil(sqrt(n))
			for i in range(2, t + 1):
				if n % i == 0:
					return False
			return True
		x = str(num)
		n = len(x)
		i = 0
		while i < n:
			t = num % 10
			num //= 10
			num += 10 ** (n - 1) * t
			if not isPrime(num):
				return 0
			i += 1
		return 1


class Solution:

	def isCircularPrime(self, n):
		strNum = str(n)
		for i in range(len(strNum)):
			if not self.isPrime(int(strNum[i:] + strNum[0:i])):
				return 0
		return 1

	def isPrime(self, n):
		if n == 1:
			return False
		for i in range(2, n // 2 + 1):
			if n % i == 0:
				return False
		return True


import math

class Solution:

	def isCircularPrime(self, n):

		def isPrime(num: int) -> bool:
			if num == 1:
				return False
			i = 2
			while i * i <= num:
				if num % i == 0:
					return False
				i += 1
			return True
		l = int(math.log10(n)) + 1
		for i in range(1, l + 1):
			ld = n % 10
			n //= 10
			n = ld * 10 ** (l - 1) + n
			if not isPrime(n):
				return 0
		return 1


class Solution:

	def isprime(self, n):
		if n == 1 or n == 0:
			return 0
		for i in range(2, n):
			if n % i == 0:
				return False
		return True

	def isCircularPrime(self, n):
		s = n
		l = len(str(n))
		if l == 1:
			if self.isprime(s):
				return 1
			return 0
		for i in range(l):
			s = s % 10 * 10 ** (l - 1) + int(s / 10)
			if not self.isprime(s):
				return 0
		return 1


class Solution:

	def isCircularPrime(self, n):

		def check(num):
			if num == 1:
				return False
			i = 2
			while i * i <= num:
				if num % i == 0:
					return False
				i += 1
			return True
		mod = 10 ** (len(str(n)) - 1)
		ans = 0
		length = len(str(n))
		for i in range(length):
			if check(n):
				ans += 1
			if mod >= 1:
				div = n // mod
				rem = n % mod
				n = rem * 10 + div
		return 1 if ans == length else 0


import math

class Solution:

	def isCircularPrime(self, n):

		def isPrime(num):
			if num < 2:
				return False
			prime_result = [1] * (num + 1)
			prime_result[0] = 0
			prime_result[1] = 0
			for val in range(2, int(math.ceil(math.sqrt(num))) + 1):
				if prime_result[val] == 1:
					for index in range(val ** 2, num + 1, val):
						prime_result[index] = 0
			if prime_result[num]:
				return True
			return False
		digits = len(str(n))
		tot = digits
		temp = str(n)
		while digits > 0:
			digits = digits - 1
			if not isPrime(int(temp)):
				return 0
			rem = str(int(temp) % 10)
			temp = str(int(temp) // 10)
			rem = rem + '0' * (tot - 1)
			temp = str(int(rem) + int(temp))
		return 1


import math

def isprime(n):
	if n > 1:
		for i in range(2, int(math.sqrt(n)) + 1):
			if n % i == 0:
				return 0
		return 1
	return 0

class Solution:

	def isCircularPrime(self, n):
		d = len(str(n))
		ans = 1
		if isprime(n) != 1:
			return 0
		if d == 1:
			return 1
		d -= 1
		num = n
		r = num % 10
		num = num // 10 + 10 ** d * r
		if isprime(num) != 1:
			ans = 0
		while num != n:
			r = num % 10
			num = num // 10 + 10 ** d * r
			if isprime(num) != 1:
				ans = 0
		return ans


class Solution:

	def isCircularPrime(self, n):
		a = []
		i = 0
		while i < len(str(n)):
			if len(a) == 0:
				a.append(str(n))
			else:
				str1 = str(a[i - 1])
				b = str1[1:] + str1[0]
				a.append(b)
			i += 1
		if '1' in a:
			return 0
		for i in range(len(a)):
			temp = int(a[i])
			for j in range(2, temp):
				if temp % j == 0 or temp == 1:
					return 0
		return 1


class Solution:

	def isPrime(self, n):
		if n <= 1:
			return 0
		for i in range(2, n):
			if n % i == 0:
				return 0
		return 1

	def isCircularPrime(self, n):
		tm = n
		cntd = 0
		while tm > 0:
			cntd += 1
			tm = tm // 10
		ans = 0
		for _ in range(cntd):
			if self.isPrime(n):
				ans += 1
			l = n % 10
			n = n // 10
			n = l * 10 ** (cntd - 1) + n
		if ans == cntd:
			return 1
		return 0


class Solution:

	def isCircularPrime(self, n):
		s = str(n)
		count = 0
		for i in range(0, len(s)):
			a = s[i:] + s[:i]
			b = int(a)
			count1 = 0
			if b == 1:
				return 0
			for i in range(1, b + 1):
				if b % i == 0:
					count1 += 1
			if count1 == 2:
				count += 1
		if count == len(s):
			return 1
		else:
			return 0


import math

class Solution:

	def isCircularPrime(self, n):

		def isprime(xx):
			up = int(xx ** 0.5)
			for i in range(2, up + 1):
				if xx % i == 0:
					return 0
			return 1
		if n == 1:
			return 0
		if n == 2 or n == 3 or n == 5 or (n == 7):
			return 1
		temp = n
		nums = []
		summ = 0
		while temp > 0:
			x = temp % 10
			summ += x
			if x in [0, 2, 4, 5, 6, 8]:
				return 0
			else:
				nums.append(x)
			temp //= 10
		if summ % 3 == 0:
			return 0
		i = 0
		l = len(nums)
		while i < l:
			if not isprime(n):
				return 0
			x = n % 10
			n = n // 10
			n = x * 10 ** (l - 1) + n
			i += 1
		return 1


from itertools import permutations

class Solution:

	def isPrime(self, n):
		if n == 1:
			return False
		for j in range(2, n):
			if n % j == 0:
				return False
		return True

	def isCircularPrime(self, n):
		if not self.isPrime(n):
			return 0
		rotations = self.cal(n)
		for ele in rotations:
			if not self.isPrime(ele):
				return 0
		return 1

	def numberofDigits(self, n):
		cnt = 0
		while n > 0:
			cnt += 1
			n //= 10
		return cnt

	def cal(self, num):
		digit = self.numberofDigits(num)
		if digit == 1:
			return [num]
		powTen = pow(10, digit - 1)
		rotations = []
		for i in range(digit - 1):
			firstDigit = num // powTen
			left = num * 10 + firstDigit - firstDigit * powTen * 10
			rotations.append(left)
			num = left
		return rotations


class Solution:

	def isCircularPrime(self, n):

		def isPrime(num):
			if num < 2:
				return False
			if num < 4:
				return True
			for i in range(2, int(num ** 0.5) + 2):
				if num % i == 0:
					return False
			return True
		num = str(n)
		n = len(num)
		for i in range(n):
			if isPrime(int(num)) == False:
				return 0
			num = num[-1] + num[:-1]
		return 1