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;
    }
}

你可能感兴趣的:(cf,算法)