I want to find a number[i] of infinite sequence but it takes a long time in the following input.
Let's consider an infinite sequence of digits constructed of ascending powers of 10 written one after another. Here is the beginning of the sequence:
110100100010000...You are to find out what digit is located at the definite position of the sequence.Input There is the only integer N in the first line (1 ≤ N ≤ 65535). The i-th of N left lines contains the integer K[i] — the number of position in the sequence (1 ≤ K[i] ≤ 231 − 1).
Output You are to output N digits 0 or 1 separated with a space. More precisely, the i-th digit of output is to be equal to the Ki-th digit of described above sequence.
INPUT
4 3 14 7 6OUTPUT
0 0 1 0
Here's my code
x = input() a = [] for i in range(x): y = input() a.append(y) b = '1' c = 1 for i in range(100): c *= 10 b += str(c) for i in range(x): print b[a[i]-1],
K[i]can be a lot larger (1 ≤ K[i] ≤ 231 − 1, where I assume "231" is a copy-and-paste error and means 2^31) and the approach of this program doesn't hold. - Carsteni, whatK[i]must be without building the string. - jonrsharpe