Reverse Engineering
It's a life of crime for you! You and your friends just broke into Bonython Bank, and now, it's time to open their safe containing a million Leetcoins!
As the tech guru, you know find the code for the safe. Given its 4-digit "seed", , you must repeat the following operation
times:
Let
be the number you get after rearranging the digits of
in descending order.
Let
be the number you get after rearranging the digits of
in ascending order.
Set
.
Pad
with zeros, if necessary. For example, 11 -> 0011.
The final value of will be the code for the safe.
Quick, the police will get to your location in no time! What is the safe's code?
Input
The first line of each test case contains a 4-digit integer , the starting value for the operations.
The second line contains an integer (
), the number of times you need to perform the operation.
Output
For each test case, output the code for the safe.
Example
Input
2413
2
Output
8352
We need to do the operation twice.
Operation 1:
.
Operation 2:
.
The final value of is 8352, so the safe's code is 8352.
Example
Input
1111
100
Output
0000
We need to do the operation 100 times.
Operation 1:
.
All future operations will make , so we know that the safe's code is 0.
Comments