P3922 Middle School Math Problem

Background

Cirno: I got it! The answer is $-1 \ 0$, because Gensokyo has no teleporter! Rumia: I really can’t with you... Fine, let’s do another middle school math problem. Saying that, Rumia wrote down a sequence: $ 1 , 2 , 4 , 8 , 16 , 32 , 64 , 128 , \cdots , 2048 , 4096 , 8192 , 16384 , \cdots $.

Description

Rumia: The general term of this sequence is $ x_n = 2^{n-1} $. Now, find how many numbers among the first $ k+1 $ terms have the first digit $4$ (for example, $4096$). The input is “encrypted”. See [Input Format] for details.

Input Format

One line with two positive integers, $ t $ and $ k_0 $. If $ t = 1 $, then the actual $ k $ is $ k_0 $. If $ t = 0 $, then the actual $ k $ is $ 10^{k_0} $.

Output Format

A single integer $ ans $, representing how many numbers have the first digit $4$.

Explanation/Hint

For $ 30\% $ of the testdata, $ k_0 \leq 10^7, \ t = 1 $. For $ 70\% $ of the testdata, $ k_0 \leq 10^9, \ t = 1 $. For another $ 30\% $ of the testdata, $ k_0 \leq 233, \ t = 0 $. For $ 100\% $ of the testdata, $ k_0 \geq 1 $. Translated by ChatGPT 5