A n digit number x is called **Keith number** if it appears in a special sequence (defined below) generated using its digits. The special sequence has first n terms as digits of x and other terms are recursively evaluated as sum of previous n terms.The task is to find if a given number is Keith Number or not.

**Examples**

```
Input : x = 197
Output : 1
197 has 3 digits, so n = 3
The number is Keith because it appears in the special
sequence that has first three terms as 1, 9, 7 and
remaining terms evaluated using sum of previous 3 terms.
1, 9, 7, 17, 33, 57, 107,
```**197**, .....
Input : x = 12
Output : 0
The number is not Keith because it doesn't appear in
the special sequence generated using its digits.
1, 2, 3, 5, 8, 13, 21, .....
Input : x = 14
Output : 1
14 is a Keith number since it appears in the sequence,
1, 4, 5, 9, **14**, ...

**Input:**

The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each line contains an integer x.

**Output:**

For each test case in a new line print 1 if the no is a Keith number else print 0.

**Constraints:**

1 <= T <= 10000

1 <= x <= 10000

**Example:
Input:**

2

14

10

1

0

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.

manishgupta8497 | 607 |

ARUN_PUNDIR | 309 |

vvggfggcg | 300 |

KhyatiSoneji | 272 |

greatpan | 241 |

manishgupta8497 | 607 |

ARUN_PUNDIR | 567 |

KhyatiSoneji | 501 |

Abhimanyu_kumar | 457 |

vvggfggcg | 453 |

blackshadows | 5333 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.