# Computing the nth term of a sequence when n is really large

How to find the, say, 28383rd term of the sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 0, 1, 1, 1, 2,.... ?

EDIT: The sequence is the sequence of digits of positive integers in order.

thanks,

-
I assume the sequence consists of the digits of the sequence of all positive integers in order? In any case, you should clarify this. – Ted Sep 4 '11 at 20:21
Yes, you got it right. I'm sorry if I missed any detail.:) – yati sagade Sep 4 '11 at 20:34
@yati sagade, Please take a look at this thread: math.stackexchange.com/questions/626216/… – Artem Jan 3 '14 at 20:15

Hint: think about how many terms are produced by the 1 digit numbers, then how many terms are produced by the 2 digit numbers, etc. That will allow you to get that you are in the $m$ digit numbers and the end of the $m-1$ digit numbers is $p$. So now you want the $28383-p$ term of the $m$ digit numbers, and each one contributes $m$ terms.

-
great. here's what I can corroborate(tell me If I go wrong) - 9 terms from 1-digiters, 180 from 2-digiters, 1800 from 3 digiters, 18000 from 4 digiters. That leaves 8394 terms to go, all from 5 digiters. Is it the 4th digit of 9999 + 1679? pardon me if I was stupid. – yati sagade Sep 4 '11 at 20:30
Why $180$ for 2-digits? You should start counting at $10$ and stop at $99$, which should give you $90$ numbers. Similarly you get $900$ numbers with $3$ digits, $9000$ for $4$ digits and in general $9\cdot 10^{k-1}$ for $k$ digits. – TMM Sep 4 '11 at 20:34
...unless you meant to count the digits, in which case $90\cdot2 = 180$ is correct, but $900\cdot3 = 2700$ etc. – TMM Sep 4 '11 at 20:35
Yes that's what I meant, since the terms in this sequence are digits. What next? was I right till the last part? – yati sagade Sep 4 '11 at 20:39
@yati sagade: So the one through three digit numbers give 9+180+2700=2889 digits, leaving 25494. 6373 [=floor(25494/4)] four digit numbers (ending in 7372) give 25492 more, so we want the second digit of 7373, which is 3. – Ross Millikan Sep 4 '11 at 21:08

Just to complement Ross Millikan's answer, notice that using digits of your sequence as decimal fractional digits produces a number, known as Champernowne constant.

For verification purposes you could use Mathematica:

In[130]:= RealDigits[ChampernowneNumber[], 10, 1, -28383]

Out[130]= {{3}, -28382}

-
That is interesting, Sasha. – yati sagade Sep 4 '11 at 20:49

There is a formula that can be used to compute this based on the sum:

$$g(n)=\sum_{1\leqslant k \leqslant n} 9 \times 10^{k-1} \times k = \frac{ 9(n+1)10^n-10^{n+1}+1} {9} \qquad k,n \in \mathbb{Z^+}$$

Plug it in to:

$$p=10^{\lceil a \rceil} -1 - \left\lfloor \frac{g( \lceil a \rceil) - g(a)}{\lceil a \rceil} \right\rfloor, g(a) = n \qquad a \in \mathbb{R^+}$$

And now find $r$

$$r = g(\lceil a \rceil ) - g(a) \mod \lceil a \rceil$$ The $r$ gives you the index of the $n$th digit in the number $p$.

and get the digit from: $$p = (a_r\dots a_1a_0)$$

-