Sequence with Digits 2023-03-14 16:14 8阅读 0赞 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 x without leading zeroes. For examples refer to notes.Your task is calculate aK for given a1 and K. Input The first line contains one integer t(1≤t≤1000) — the number of independent test cases. Each test case consists of a single line containing two integers a1 and K (1≤a1≤1018, 1≤K≤1016) separated by a space. Output For each test case print one integer aKaK on a separate line. Example input 8 1 4 487 1 487 2 487 3 487 4 487 5 487 6 487 7 ootput 42 487 519 528 544 564 588 628 Note a1=487 a2=a1+minDigit(a1)⋅maxDigit(a1)=487+min(4,8,7)⋅max(4,8,7)=487+4⋅8=519 a3=a2+minDigit(a2)⋅maxDigit(a2)=519+min(5,1,9)⋅max(5,1,9)=519+1⋅9=528 a4=a3+minDigit(a3)⋅maxDigit(a3)=528+min(5,2,8)⋅max(5,2,8)=528+2⋅8=544 a5=a4+minDigit(a4)⋅maxDigit(a4)=544+min(5,4,4)⋅max(5,4,4)=544+4⋅5=564 a6=a5+minDigit(a5)⋅maxDigit(a5)=564+min(5,6,4)⋅max(5,6,4)=564+4⋅6=588 a7=a6+minDigit(a6)⋅maxDigit(a6)=588+min(5,8,8)⋅max(5,8,8)=588+5⋅8=628 #include<stdio.h> int fmax(int n) { int res=n%10; while(n) { if(res<n%10) { res=n%10; } n=n/10; } return res; } int fmin(int n) { int res=n%10; while(n) { if(res>n%10) { res=n%10; } n=n/10; } return res; } int fmn(int n) { return n+fmax(n)*fmin(n); } int main() { int t=0; scanf("%d",&t); while(t--) { int a1,k=0; scanf("%d%d",&a1,&k); for(int i=1;i<k;i++) { a1=fmn(a1); } printf("%d\n",a1); } } 文章版权声明:注明蒲公英云原创文章,转载或复制请以超链接形式并注明出处。
相关 Revolving Digits 算法: 扩展KMP + KMP找循环节 ![ContractedBlock.gif][] ![ExpandedBlockStart.gif][] inclu 港控/mmm°/ 2021年10月23日 19:56/ 0 赞/ 51 阅读
相关 [面试题] Find next higher number with same digits Find next higher number with same digits. Example 1 : if num = 25468, o/p = 25486 - 日理万妓/ 2021年12月03日 15:23/ 0 赞/ 48 阅读
相关 AVC sequence header & AAC sequence header 推送H.264和AAC的重要前提 RTMP的音视频流的封装形式和FLV格式相似, 流媒体服务器向客户端发送包含H264和AAC的RTMP直播流,需要首先发送: AVC 素颜马尾好姑娘i/ 2022年04月03日 11:24/ 0 赞/ 32 阅读
相关 ValueError: setting an array element with a sequence.错误处理。。。 对于这个错误,看了很多的博客资料。都说数组元素没有对齐(多半是训练词向量时出现了空格),找到相应的列补充元素就行,看了之后心累啊。。。。 小编做自然语言处理,几个G的文本啊 柔光的暖阳◎/ 2022年05月14日 09:47/ 0 赞/ 44 阅读
相关 258. Add Digits Given a non-negative integer `num`, repeatedly add all its digits until the result has o 青旅半醒/ 2022年07月15日 09:27/ 0 赞/ 16 阅读
相关 258. Add Digits Given a non-negative integer `num`, repeatedly add all its digits until the result has o 本是古典 何须时尚/ 2022年07月15日 09:27/ 0 赞/ 17 阅读
相关 sequence to sequence [论文 Sequence to Sequence Learning with Neural Networks][Sequence to Seque Myth丶恋晨/ 2022年07月15日 18:39/ 0 赞/ 22 阅读
相关 LeetCode 258. Add Digits 为了保持了解比较有意思的解法算法,所以决定每天看几道LeetCode上面的题,现在开始: 题目: Given a non-negative integer num, r 川长思鸟来/ 2022年07月27日 21:39/ 0 赞/ 15 阅读
相关 《STTR:Revisiting Stereo Depth Estimation From a Sequence-to-Sequence Perspective with Transformers》 参考代码:[stereo-transformer][] 1. 概述 > 导读:这篇文章通过transformer机制实现了一种立体匹配算法(STTR),在该方法中将立体 Bertha 。/ 2022年09月11日 12:12/ 0 赞/ 18 阅读
相关 Sequence with Digits Let’s define the following recurrence : an+1=an+minDigit(an)⋅maxDigit(an).an+1=an+minDig 朱雀/ 2023年03月14日 16:14/ 0 赞/ 9 阅读
还没有评论,来说两句吧...