Sequence with Digits
题意
(a_{n+1}=a_n+minDigit(a_n) imes maxDigit(a_n))
给出(a_1),和(k),求(a_k)。
思路
(k)的范围是(10^{18}),肯定不会是暴力。
只要(minDigig(a_i)==0),就可以直接退出循环
代码
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<vector>
#define pb push_back
typedef long long ll;
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
const int N = 1e6+10;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
ll n,k;
scanf("%lld%lld",&n,&k);
for(ll i=1;i<k;i++)
{
ll minn=inf,maxn=-inf;
ll tmp=n;
while(tmp)
{
ll now=tmp%10;
minn=min(minn,now);
maxn=max(maxn,now);
tmp/=10;
}
n+=minn*maxn;
if(minn==0) break;
}
printf("%lld
",n);
}
return 0;
}