CF1355A.Sequence with Digits
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let's define the following recurrence: $$a_{n+1} = a_{n} + minDigit(a_{n}) \cdot maxDigit(a_{n}).$$
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.
Your task is calculate aK for given a1 and K.
我们定义如下递推关系:
a_{n+1} = a_{n} + \minDigit(a_{n}) \cdot \maxDigit(a_{n}).其中,\minDigit(x) 和 \maxDigit(x) 分别表示 x 的十进制表示(不含前导零)中最小和最大的数字。示例请参见注释部分。
你的任务是:给定初始值 a1 和正整数 K,计算 aK。
输入格式
The first line contains one integer t (1≤t≤1000) — the number of independent test cases.
Each test case consists of a single line containing two integers a1 and K (1≤a1≤1018, 1≤K≤1016) separated by a space.
第一行包含一个整数 t(1≤t≤1000)—— 表示独立测试用例的数量。
每个测试用例由一行组成,该行包含两个整数 a1 和 K(1≤a1≤1018,1≤K≤1016),以空格分隔。
输出格式
For each test case print one integer aK on a separate line.
对于每个测试用例,在单独一行输出一个整数 aK。
输入输出样例
输入#1
8 1 4 487 1 487 2 487 3 487 4 487 5 487 6 487 7
输出#1
42 487 519 528 544 564 588 628
说明/提示
a1=487
a2=a1+minDigit(a1)⋅maxDigit(a1)=487+min(4,8,7)⋅max(4,8,7)=487+4⋅8=519
a3=a2+minDigit(a2)⋅maxDigit(a2)=519+min(5,1,9)⋅max(5,1,9)=519+1⋅9=528
a4=a3+minDigit(a3)⋅maxDigit(a3)=528+min(5,2,8)⋅max(5,2,8)=528+2⋅8=544
a5=a4+minDigit(a4)⋅maxDigit(a4)=544+min(5,4,4)⋅max(5,4,4)=544+4⋅5=564
a6=a5+minDigit(a5)⋅maxDigit(a5)=564+min(5,6,4)⋅max(5,6,4)=564+4⋅6=588
a7=a6+minDigit(a6)⋅maxDigit(a6)=588+min(5,8,8)⋅max(5,8,8)=588+5⋅8=628
a1=487
a2=a1+minDigit(a1)⋅maxDigit(a1)=487+min(4,8,7)⋅max(4,8,7)=487+4⋅8=519
a3=a2+minDigit(a2)⋅maxDigit(a2)=519+min(5,1,9)⋅max(5,1,9)=519+1⋅9=528
a4=a3+minDigit(a3)⋅maxDigit(a3)=528+min(5,2,8)⋅max(5,2,8)=528+2⋅8=544
a5=a4+minDigit(a4)⋅maxDigit(a4)=544+min(5,4,4)⋅max(5,4,4)=544+4⋅5=564
a6=a5+minDigit(a5)⋅maxDigit(a5)=564+min(5,6,4)⋅max(5,6,4)=564+4⋅6=588
a7=a6+minDigit(a6)⋅maxDigit(a6)=588+min(5,8,8)⋅max(5,8,8)=588+5⋅8=628
输入解题思路,AI测评打分。不知道怎么写?