Is digital root of N a prime?
Submissions: 1838   Accuracy:

28.21%

  Difficulty: Basic   Marks: 1

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

Input:
The first line of the input contains a single integer T, denoting the number of test cases. Then T test case follows. Each testcase contains a single line having N as
input.

Ouput:
For each testcase, print 1 if the digitalRoot(N) is prime, else print 0.

Constraints:
1 <= T <= 110
1 <= N <= 104

Example:
Input:
3
89
45
12

Output:
0
0
1

Explanation:
For testcase 1: DigitalRoot(89)=>17=>1+7=>8; not a prime.
For testcase 3: DigitalRoot(12)=>1+2=>3; a prime number.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Ankit Sharma
Author: Soul_xhacker


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.