luogu#P9766. [ROIR 2021] 好数 (Day 2)

[ROIR 2021] 好数 (Day 2)

Background

Translated from ROIR 2021 Day 2 T2 Числа

Problem Description

A type 1 good number is a number in which all digits are the same.

A type 2 good number is a number that satisfies any one of the following conditions:

  • It is a type 1 good number.
  • Let tt be the number of digits of the number. Then the digits are the same on t1t-1 positions, and there are no leading zeros.

Now given an xx, find the first type k+1k+1 good number yy such that yxy \ge x

Input Format

The first line contains an integer xx

The second line contains an integer kk

Output Format

Output one integer yy in one line。

700
0
777
700
1
700

Hint

For all subtasks, 1x10171 \le x \le 10^{17}, k{0,1}k \in \{0,1\}

Constraints

Subtask ID Special Constraints Points
11 1x1051 \le x \le 10^5, k=0k=0 1515
22 k=0k=0 2020
33 1x1051 \le x \le 10^5 2121
44 No special constraints 4444

Translated by ChatGPT 5