Timer is Running

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.

Umakant_Dubey | 314 |

binod_gotiyo | 307 |

lone_walker | 304 |

NaveenGarg2 | 235 |

ArpitGupta8 | 233 |

saiujwal13083 | 799 |

ppsvikhyat17 | 712 |

generic_coder | 630 |

lone_walker | 590 |

NaveenGarg2 | 554 |

blackshadows | 5448 |

Ibrahim Nash | 5438 |

akhayrutdinov | 5111 |

mb1973 | 4976 |

Quandray | 4752 |

Login to report an issue on this page.