Let's define the following recurrence:
an+1=an+minDigit(an)⋅maxDigit(an).an+1=an+minDigit(an)⋅maxDigit(an).
Here minDigit(x)minDigit(x) and maxDigit(x)maxDigit(x) are the minimal and maximal digits in the decimal representation of xx without leading zeroes. For examples refer to notes.
Your task is calculate aKaK for given a1a1 and KK .
Input
The first line contains one integer tt (1≤t≤10001≤t≤1000 ) — the number of independent test cases.
Each test case consists of a single line containing two integers a1a1 and KK (1≤a1≤10181≤a1≤1018 , 1≤K≤10161≤K≤1016 ) separated by a space.
Output
For each test case print one integer aKaK on a separate line.
Example
Input
Copy
8 1 4 487 1 487 2 487 3 487 4 487 5 487 6 487 7
Output
Copy
42 487 519 528 544 564 588 628
按题目说的模拟,特别地,一个数里出现0的时候直接输出当前数并break。
#include <bits/stdc++.h> using namespace std; long long a,k; int main() { int t; cin>>t; while(t--) { cin>>a1>>k; int cnt; if(k==1) { cout<<a<<endl; continue; } for(cnt=2;cnt<=k;cnt++) { int mmax=-1,mmin=10; long long temp=a; while(temp)//拆分数字 { int dig=temp%10; mmax=max(mmax,dig); mmin=min(mmin,dig); temp/=10; } if(k==cnt) { cout<<a+mmax*mmin<<endl; } else if(mmin==0)//出现0了 累加之后还是0 因此直接输出 终止循环 { cout<<a+mmax*mmin<<endl; break; } else a+=mmax*mmin; } } }