Codeforces Round #643 (Div. 2) A. Sequence with Digits(暴力)

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 (1t10001≤t≤1000 ) — the number of independent test cases.

Each test case consists of a single line containing two integers a1a1 and KK (1a110181≤a1≤1018 , 1K10161≤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;
        }
    }
}
复制代码

 



posted @   脂环  阅读(528)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示
主题色彩