Problem: https://codeforces.com/contest/1355/problem/A
Let's define the following recurrence: an+1=an+minDigit(an)⋅maxDigit(an). Here minDigit(x) and 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 aK on a separate line.
Example:
INPUT:
8
1 4
487 1
487 2
487 3
487 4
487 5
487 6
487 7
OUTPUT:
42
487
519
528
544
564
588
628
I am getting the correct output when I run it in BlueJ on my computer but it says "Runtime error on test 1" on Codeforces. This is my code:
import java.util.*;
public class b
{
static Scanner sc=new Scanner(System.in);
public static void main()
{
long t=sc.nextLong();
for(int i=0;i<t;i++)
{
long a=sc.nextLong();
long k=sc.nextLong();
for(long j=1;j<k;j++){
long c=a,min=9,max=0;
while(c>0)
{
long rem=c%10;
if(rem<min)
min=rem;
if(rem>max)
max=rem;
c=c/10;
}
a=a+min*max;
} System.out.println(a);
}
}
}