#K4031. Find the Nth Character in the Concatenated Sequence of Natural Numbers

    ID: 26614 Type: Default 1000ms 256MiB

Find the Nth Character in the Concatenated Sequence of Natural Numbers

Find the Nth Character in the Concatenated Sequence of Natural Numbers

Consider the infinite sequence formed by concatenating all natural numbers (starting from 0) into one continuous string: \(S = 012345678910111213...\). Given a non-negative index \(n\) (where \(n\) is 0-indexed), your task is to determine the character at position \(n\) in this sequence.

For example, if \(n = 5\), the resulting character is '5' because the sequence begins with "012345...". Similarly, if \(n = 15\), the answer is '2'.

You need to read an integer from stdin and output the corresponding character to stdout.

inputFormat

Input is given via standard input. It consists of a single non-negative integer (n) on a single line, where (n) represents the 0-indexed position in the concatenated sequence of natural numbers.

outputFormat

Output a single character (digit) to standard output, which is the (n)th character in the concatenated string of natural numbers.## sample

5
5