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 (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; } } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 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框架的用法!