#P10253. 说唱

    ID: 10958 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>数学高精度洛谷原创O2优化洛谷月赛

说唱

Background

A formal statement of the problem is given at the end of the description.

Problem Description

ZHY practices rap in an empty room.

At the beginning, ZHY makes a sound with intensity xx. This sound collides with the walls and produces an echo with intensity x10\lfloor \frac x {10} \rfloor. The echo continues to collide with the walls, producing an echo of the echo... until the echo intensity becomes 00.

There is also a radio in the room, which records all sounds (including the initial sound and all echoes). Unfortunately, ZHY accidentally broke the radio. Now, the radio can only display the sum of the intensities of all recorded sounds, yy. Can you compute the intensity of ZHY's initial sound from this only information? Since the radio is very old, it may malfunction and show an incorrect number. In such cases, you need to output 1-1.

Formal statement

Define a function as follows:

$$f(x)=\begin{cases} 0 & x = 0 \\ x+f(\lfloor\frac{x}{10}\rfloor) & x > 0 \end{cases}$$

For example, f(123)=123+12+1=136f(123)=123+12+1=136.

Given a number yy, determine whether there exists a unique number xx such that f(x)=yf(x)=y. If it exists, output xx; otherwise, output 1-1.

Input Format

This problem contains multiple test cases.

The first line contains an integer TT, denoting the number of test cases.

Each test case contains one line with an integer yy.

Output Format

For each test case, if there exists a unique xx corresponding to this yy, output xx. Otherwise, output -1.

2
12
136
11
123
3
10
123
7510
-1
111
6761

Hint

Subtaskid\mathrm{Subtask} \kern{2pt} \mathrm{id} yy Special property Score
11 <1000< 1000 None 1010
22 <106< 10^6 1515
33 <10100000< 10^{100000} S9S\le 9 1010
44 S10S\le 10 2020
55 <103000< 10^{3000} None 1515
66 <10500000< 10^{500000} 3030

In the “Special property” column, SkS\le k means: “If a solution exists, the sum of all digits of xx is at most kk.”

For all testdata, 1T101\le T\le 10, 0y<105000000 \le y < 10^{500000}.

Translated by ChatGPT 5