OTHS Coding Competition 4 P2 - Furina's Rounding

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 2.0s
Java 4.0s
Python 4.0s
Memory limit: 512M
Java 1G
Python 1G

Author:
Problem types

Optimistic as usual, Furina rounds all numbers up to 1 significant digit. Unfortunately for her, Neuvillette requires precise numbers for official documents. Given the precise number as an integer N, Neuvillette needs to calculate an adjustment value that must be subtracted from Furina's rounded number.

Since these numbers may be extremely large, mental math would be insufficient.

Seeing your outstanding programming reputation, Neuvillette asks you to compute the adjustment value as previously described.

Formally, calculate the non-negative integer difference between N and the smallest integer greater than or equal to N with exactly one non-zero digit.

Constraints

1 \le N < 10^{10^6}

Subtask 1 [20%]

1 \le N < 10^{6}

Subtask 2 [30%]

1 \le N < 10^{18}

Subtask 3 [50%]

No additional constraints.

Note: You do not need to pass the last sample to earn points on the first two subtasks.

Sample Input 1

299

Sample Output 1

1

Explanation for Sample 1

Furina rounds 299 to up 3 \times 10^2. The required adjustment value is 1.

Sample Input 2

8

Sample Output 2

0

Explanation for Sample 2

Furina's rounded number is the same. Therefore, no adjustment is needed.

Sample Input 3

60000

Sample Output 3

0

Explanation for Sample 3

Furina's rounded number is the same. Therefore, no adjustment is needed.

Sample Input 4

237862394932878926523237

Sample Output 4

62137605067121073476763

Explanation for Sample 4

Furina rounds 237862394932878926523237 to up 3 \times 10^{23}. The required adjustment value is 62137605067121073476763.


Comments

There are no comments at the moment.