A. Sequence with Digits

A. Sequence with Digits

A.数字序列

time limit per test: 1 second
每次测试的时间限制:1秒

memory limit per test: 256 megabytes
每次测试的内存限制:256兆字节

input: standard input
input: standard input

output: standard output
output: standard output

Let’s define the following recurrence:
Let’s define the following recurrence:

an+1= an + minDigit(an) . maxDigit(an).
A+1=an+minDigit(An)最大数字(AN)

Here minDigit(x ) and max Digit(x ) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For
Here minDigit(x ) and max Digit(x ) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For

examples refer to notes.
examples refer to notes.

Your task is calculate aK for given a1 and K.
Your task is calculate aK for given a1 and K.

Input
输入

The first line contains one integert(1≤t < 1000)一the number of independent test cases.
第一行包含一个整数(1≤t<1000)一独立测试用例数。

Each test case consists of a single line containing two integers a1 andK (1≤a1≤1018.1≤K≤101) separated by a space.
Each test case consists of a single line containing two integers a1 andK (1≤a1≤1018.1≤K≤101) separated by a space.

Output
输出量

For each test case print one integer ak on a separate line.
对于每个测试用例,在单独的行上打印一个整数AK。

模拟

ll min(ll n)
{
    ll a = 11;
    while(n)
    {
        a = min(a,n%10);
        n /= 10;
        if(a == 0) break;
    }
    return a;
}
ll max(ll n)
{
    ll a = -1;
    while(n)
    {
        a = max(a,n%10);
        n/= 10;
        if(a == 9) break;
    }
    return a;
}
int main()
{

    int t;
    cin >> t;
    while(t--)
    {
        ll n,k;
        cin >> n >> k;
        for(int i = 1;i < k;++i)
        {
            if(min(n) == 0)
             break;
            n += min(n)*max(n);
        }
        cout << n << endl;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值