1355A.md (1755B)
1 Source: https://codeforces.com/problemset/problem/1355/A 2 3 A. Sequence with Digits 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Let's define the following recurrence: $$a_{n+1} = a_{n} + minDigit(a_{n}) \cdot maxDigit(a_{n}).$$ 22 23 Here $minDigit(x)$ and $maxDigit(x)$ are the minimal and maximal digits in the decimal representation of $x$ without leading zeroes. For examples refer to notes. 24 25 Your task is calculate $a_{K}$ for given $a_{1}$ and $K$. 26 27 Input 28 29 The first line contains one integer $t$ ($1 \le t \le 1000$) — the number of independent test cases. 30 31 Each test case consists of a single line containing two integers $a_{1}$ and $K$ ($1 \le a_{1} \le 10^{18}$, $1 \le K \le 10^{16}$) separated by a space. 32 33 Output 34 35 For each test case print one integer $a_{K}$ on a separate line. 36 37 Example 38 39 Input 40 41 ``` 42 8 43 1 4 44 487 1 45 487 2 46 487 3 47 487 4 48 487 5 49 487 6 50 487 7 51 ``` 52 53 Output 54 55 ``` 56 42 57 487 58 519 59 528 60 544 61 564 62 588 63 628 64 ``` 65 66 Note 67 68 $a_{1} = 487$ 69 70 $a_{2} = a_{1} + minDigit(a_{1}) \cdot maxDigit(a_{1}) = 487 + \min (4, 8, 7) \cdot \max (4, 8, 7) = 487 + 4 \cdot 8 = 519$ 71 72 $a_{3} = a_{2} + minDigit(a_{2}) \cdot maxDigit(a_{2}) = 519 + \min (5, 1, 9) \cdot \max (5, 1, 9) = 519 + 1 \cdot 9 = 528$ 73 74 $a_{4} = a_{3} + minDigit(a_{3}) \cdot maxDigit(a_{3}) = 528 + \min (5, 2, 8) \cdot \max (5, 2, 8) = 528 + 2 \cdot 8 = 544$ 75 76 $a_{5} = a_{4} + minDigit(a_{4}) \cdot maxDigit(a_{4}) = 544 + \min (5, 4, 4) \cdot \max (5, 4, 4) = 544 + 4 \cdot 5 = 564$ 77 78 $a_{6} = a_{5} + minDigit(a_{5}) \cdot maxDigit(a_{5}) = 564 + \min (5, 6, 4) \cdot \max (5, 6, 4) = 564 + 4 \cdot 6 = 588$ 79 80 $a_{7} = a_{6} + minDigit(a_{6}) \cdot maxDigit(a_{6}) = 588 + \min (5, 8, 8) \cdot \max (5, 8, 8) = 588 + 5 \cdot 8 = 628$