Given a number N, you need to find if its digital root is prime or not. DigitalRoot of a number is the repetitive sum of its digits until we get a single-digit number.
Eg.DigitalRoot(191)=1+9+1=>11=>1+1=>2
Example 1:
Input:
N = 89
Output:
0
Explanation:
DigitalRoot(89)=>17=>1+7=>8; not a prime.
Example 2:
Input:
N = 12
Output:
1
Explanation:
DigitalRoot(12)=>1+2=>3; a prime number.
Your Task:  
You don't need to read input or print anything. Your task is to complete the function digitalRoot() which takes an integer N as an input parameter and return 1 if its digital root is a prime number otherwise return 0.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{4}

Difficulty: EASY
Tags: Mathematics
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3

class Solution:
    def digitalRoot(self, N):
    	#code here 

Solutions:
class Solution:

	def digitalRoot(self, N):
		while len(str(N)) > 1:
			d = [int(x) for x in str(N)]
			N = sum(d)
		if N == 2 or N == 3 or N == 5 or (N == 7):
			return 1
		else:
			return 0


class Solution:

	def digitalRoot(self, N):
		(digRoot, primes) = (N % 9, [2, 3, 5, 7])
		return 1 if digRoot in primes else 0


class Solution:

	def digitalRoot(self, N):
		primes = [2, 3, 5, 7]
		s = str(N)
		digits = list(map(int, ' '.join(s).split()))
		while len(digits) > 1:
			s = str(sum(digits))
			digits = list(map(int, ' '.join(s).split()))
		return 1 if int(digits[0]) in primes else 0


class Solution:

	def s(self, n):
		if n <= 9:
			return n
		return self.s(n // 10) + n % 10

	def digitalRoot(self, N):
		digitSum = self.s(N) % 9
		if digitSum == 2 or digitSum == 3 or digitSum == 5 or (digitSum == 7):
			return 1
		return 0


class Solution:

	def digitalRoot(self, N):

		def helper(n):
			m = str(n)
			if len(m) == 1:
				return n
			ans = 0
			for i in m:
				ans += int(i)
			return ans
		while len(str(N)) != 1:
			N = helper(N)
		if N == 1:
			return 0
		for i in range(2, int(N ** 0.5) + 1):
			if N % i == 0:
				return 0
		return 1


class Solution:

	def digitalRoot(self, N):
		res = [int(x) for x in str(N)]
		while len(res) != 1:
			res = sum(res)
			res = [int(x) for x in str(res)]
		if res[0] <= 1:
			return 0
		if res[0] > 1:
			for i in range(2, int(res[0] / 2) + 1):
				if res[0] % i == 0:
					return 0
			return 1


class Solution:

	def sod(self, N):
		s = 0
		while N > 0:
			x = N % 10
			s = s + x
			N = N // 10
		return s

	def digitalRoot(self, N):
		if N == 1:
			return '0'
		else:
			sum = Solution.sod(self, N)
			while sum >= 10:
				sum = Solution.sod(self, sum)
			if sum == 1 or sum == 4 or sum == 6 or (sum == 8) or (sum == 9):
				return '0'
			else:
				return '1'


class Solution:

	def digitalRoot(self, N):
		prime = [0, 0, 1, 1, 0, 1, 0, 1, 0, 0]
		root = 1 + (N - 1) % 9
		return prime[root]


class Solution:

	def digitalRoot(self, N):

		def isPrime(N):
			if N == 1:
				return 0
			if N == 2:
				return 1
			for i in range(2, int(N ** 0.5) + 1):
				if N % i == 0:
					return 0
			return 1
		return isPrime(self.digi(N))

	def digi(self, N):
		if N <= 9:
			return N
		sum = 0
		while N > 0:
			sum += N % 10
			N = N // 10
		return self.digi(sum)


class Solution:

	def digitalRoot(self, N):
		if N == 2 or N == 3 or N == 5 or (N == 7):
			return 1
		elif N > 9:
			sum = 0
			while N != 0:
				d = N % 10
				sum = sum + d
				N = N // 10
			return self.digitalRoot(sum)
		else:
			return 0


class Solution:

	def digitalRoot(self, N):
		k = N % 9
		if k == 2 or k == 3 or k == 5 or (k == 7):
			return 1
		return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.digitalRoot(N)
		print(ans)


class Solution:

	def digitalRoot(self, N):
		m = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
		while N >= 10:
			b = str(N)
			s = 0
			for i in b:
				s += m[i]
			N = s
		if N == 2 or N == 3 or N == 5 or (N == 7):
			return 1
		return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.digitalRoot(N)
		print(ans)


class Solution:

	def digitalRoot(self, N):
		temp = [2, 3, 5, 7]
		if N < 10:
			if N in temp:
				return 1
			else:
				return 0
		else:
			s = 0
			while N > 0:
				s += N % 10
				N = N // 10
			return self.digitalRoot(s)


class Solution:

	def digitalRoot(self, N):
		if N == 0:
			dgs = 0
			return 0
		if N % 9 == 0:
			dgs = 9
			return 0
		else:
			dgs = N % 9
		if dgs == 1 or dgs == 4 or dgs == 6 or (dgs == 8):
			return 0
		return 1


class Solution:

	def fun(self, n):
		if n == 0:
			return 0
		if n % 9 == 0:
			return 9
		else:
			return n % 9

	def digitalRoot(self, N):
		result = self.fun(N)
		if result in [2, 3, 5, 7]:
			return 1
		else:
			return 0