#abc273b. B - Broken Rounding

B - Broken Rounding

Score : 200200 points

问题描述

给定一个非负整数 XX,按照顺序对 i=1,2,,Ki=1,2,\dots,K 执行以下操作,并找出最终的 XX

  • XX 四舍五入到最接近的 10i10^i
    • 正式地说,将 XX 替换为 “使 YX|Y-X| 最小的最大 10i10^i 的倍数” 的 YY
    • 这里有一些示例:
      • 273273 四舍五入到最接近的 10210^2 得到 300300
      • 999999 四舍五入到最接近的 10310^3 得到 10001000
      • 100100 四舍五入到最接近的 101010^{10} 得到 00
      • 10151015 四舍五入到最接近的 10110^1 得到 10201020

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Given a non-negative integer XX, perform the following operation for i=1,2,,Ki=1,2,\dots,K in this order and find the resulting XX.

  • Round XX off to the nearest 10i10^i.
    • Formally, replace XX with YY that is "the largest multiple of 10i10^i that minimizes YX|Y-X|."
    • Here are some examples:
      • Rounding 273273 off to the nearest 10210^2 yields 300300.
      • Rounding 999999 off to the nearest 10310^3 yields 10001000.
      • Rounding 100100 off to the nearest 101010^{10} yields 00.
      • Rounding 10151015 off to the nearest 10110^1 yields 10201020.

Constraints

  • XX and KK are integers.
  • 0X<10150 \le X < 10^{15}
  • 1K151 \le K \le 15

Input

The input is given from Standard Input in the following format:

XX KK

Output

Print the answer as an integer.

Sample Input 1

2048 2

Sample Output 1

2100

XX changes as 2048205021002048 \rightarrow 2050 \rightarrow 2100 by the operations.

Sample Input 2

1 15

Sample Output 2

0

Sample Input 3

999 3

Sample Output 3

1000

Sample Input 4

314159265358979 12

Sample Output 4

314000000000000

XX may not fit into a 3232-bit integer type.

update @ 2024/3/10 11:29:45