Can you find the digit?

S = 123456789101112131415161718192021 S=123456789101112131415161718192021\ldots

Given that the string S S is the concatenation of the first 1,000,000,000 positive integers in ascending order, find the 99999999 9 th 999999999^{\text{th}} digit of S S .


Details and Assumptions:

By the x th x^{\text{th}} digit of S S , we mean the digit in the x th x^{\text{th}} place from the left in the decimal representation of S S .

Some explicit examples are :

  • The 5 th 5^{\text{th}} digit of the number 14583469 14583469 is 3 3 .
  • The 4 th 4^{\text{th}} digit of the number 143256 143256 is 2 2 .
7 9 3 6 5 2 8 4

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Nhat Minh Le
Nov 27, 2015

A simple program in Pascal.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
uses crt;

var count,num:longint;

      str:string;

begin

clrscr;

While count<999999999 do

begin

num:=num+1;

str(num,str);

count:=length(str)+count;

end;

Write(str[length(str)-(count-999999999)]);readln;

end. 

Can you write the solution for it in some modern language example C++ , Python .

Rishabh Gupta - 5 years, 6 months ago

Log in to reply

Here 's my C++ code for this problem, if it helps you. I haven't added explanations for the code at the moment, I'll post a complete solution after my exams are over if no one posts one by then.

You can easily convert this C++ code to Python code. Here 's the Python equivalent.

Prasun Biswas - 5 years, 6 months ago

Log in to reply

Do you use C++ and Python which you must buy for installations?

Lu Chee Ket - 5 years, 6 months ago

Log in to reply

@Lu Chee Ket ~\\~

"Do you use C++ and Python which you must buy for installations?"

Who told you that you must buy C++/ Python to use it? You don't buy a language. You can buy a compiler / interpreter to execute code written in a particular language but there are lots of free compilers / interpreters that work just fine.

I mostly do all my coding online. There are a lot of IDEs and terminals online that allow you to write, save, compile and run codes in many languages (C, C++, Python, Haskell, Java, etc) for free (example - Ideone , Coding Ground , etc). There's also an online C++ shell that I use sometimes (rarely).

If you want standalone (offline) compilers / interpreters / IDE to use on your PC, you can download one for free. For Python, you can download the official py3.5 or py2.10 release from the official website for free (IDLE). For C++, you can download the MinGW compiler (gcc) from various sources for free.

Prasun Biswas - 5 years, 6 months ago

Log in to reply

@Prasun Biswas Thanks for being kind to me. Are the various sources meant for free by the actual authorities?

Lu Chee Ket - 5 years, 6 months ago

Log in to reply

@Lu Chee Ket As far as I know, yes. Because otherwise, the free online IDEs would've been shut down by now by the official authorities.

Prasun Biswas - 5 years, 6 months ago

Log in to reply

@Prasun Biswas Good news to me. However, enforcement by official authorities are not necessarily there in the world we are living in. We can just hope that the official authorities can get wealth from their contribution and blessed. Thanks!

Lu Chee Ket - 5 years, 6 months ago

Better than mine I think. +1! I thought I can hardly find another Pascal user now a day.

Lu Chee Ket - 5 years, 6 months ago
Lu Chee Ket
Nov 27, 2015

There is a way we can verify with computing:

1
2
3
4
...123456787: 999999981
...123456787123456788: 999999990
...123456787123456788123456789: 999999999
...1234567871234567881234567891234567890: 1000000008

The 999999999th digit is 9 of the count at 123456789. (Please preserve the original statement rather than adding with leftmost digit to avoid confusion.)

Answer: 9 \boxed{9}

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...