INS14I - Infinite Sequence
Digo and Sharry like to play with numbers and sequences. They decide to write an infinite sequence. For this they start by choosing a number each. They start making the sequence by following these rules:
- Digo writes his number on a piece of paper. This is the 0th number of the sequence.
- Then Sharry writes his number on the paper, as many times as Digo’s number. e.g. if Digo wrote 2, then Sharry would write his number 2 times, making the total sequence of length 3.
- Then Digo writes his number on the paper, which becomes the next element of the sequence.
- Then Sharry writes his number as many times as the number indexed 1 in the sequence.
- Then Digo writes his number on the paper, which becomes the next element of the sequence.
- Then Sharry writes his number as many times as the number indexed 2 in the sequence. ... and the cycle goes on.
Now Digo starts to feel that the sequence that they are generating is very trivial. He claims he can tell the digit at the nth place without having to play the game. So Sharry challenges him to tell the digit which will come at the nth place.
Help Digo complete Sharry's challenge.
It is given that Digo chooses 4 as his number and Sharry chooses 5 as his number.
Input
First line of the input contains an integer T - the number of test cases.
T lines follow, each containing an integer N.
Output
Print T lines. For every test case, print the digit that appears in the Nth place.
Constraints
1 < T < 100
0 ≤ N < 1000000000
Sample
Input 3 0 4 7 Output 4 5 5
Explanation
The sequence is 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5 ...
hide comments
Sergej:
2018-06-06 14:14:03
Check number of testcases, please: T > 100 ? |
|
vishrut mishra:
2015-06-17 05:38:37
really enjoyed to solve it , learn a lot ;) |
|
vivek:
2014-12-22 11:59:47
AC in one go :) |
|
Pragya:
2014-08-22 14:00:55
How to declare an array with 10^9 size in C???
|
|
Shantanu Singh:
2014-06-30 11:03:53
Learned something new .Its hard to get AC without that. |
|
kiran pilli:
2014-06-22 19:23:55
please provide some tricky test cases
|
|
Surya kiran:
2014-04-13 19:37:56
@DEVENDRA : No more test cases will be provided |
|
lovecode:
2014-03-30 05:47:11
plz in running 2 i m getting wa plz someone give me more test cases plz Last edit: 2014-03-31 21:22:44 |
|
Jacob Plachta:
2014-03-26 22:27:41
There's a typo in the problem name.
|
|
Surya kiran:
2014-03-26 22:27:41
@Rivu : No more test cases will be provided |
Added by: | Surya Kiran |
Date: | 2014-03-20 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | Insomnia 2014 |