WC '02 P2 - Cow-bot

View as PDF

Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 16M

Problem types
Woburn Challenge 2002

The cows sense victory. With the monkeys "pinned" squarely in the middle of Scarberia, attending to their tender behinds, the cows have decided to go in for the kill. Before they do so, however, they must gather some intelligence. To this end, the leader of the cows, Bo Vine, has designed a robot. He calls it… (Insert drum roll here)… COW-BOT! As with every computer program, ahem, Cow-Bot has to be tested rigorously and thoroughly to ensure that there are no flaws in his implementation.

Bo Vine has fed into the robot a list of instructions that it must execute. Cow-Bot will be presented with an initial number and be given the number of iterations it must perform. He begins by considering instructions at the beginning of the list, and executes the first of these that apply. The result of the action is the number used in the following iteration, which again begins at the top of the list.

Condition Action
Number is prime Multiply by 11; e.g.: 2 \to 22
Number is a perfect square Add the reverse of the number; e.g.: 64 \to 110
Number is a palindrome Add a 4 at the end; e.g.: 11 \to 114
Number starts with a 2 Add a 5 at the front; e.g.: 21 \to 521
Number has a 7 anywhere in it Remove the last digit; e.g.: 27 \to 2
Number is divisible by 6 Remove the first digit; e.g.: 108 \to 8
Number has an even number of digits Place a 1 in the middle; e.g.: 42 \to 412
Number has an odd number of digits Add 231; e.g.: 1 \to 232

Input Specification

The first line of input contains a single integer T (1 \le T \le 50), indicating the number of test cases.
Each test case consists of one line of 2 numbers, a and b, where a (0 \le a \le 214\,783\,647), is the starting number and b (0 \le b \le 32\,767), is the number of iterations to be performed.

Output Specification

For each case, output the number that is the final result of all computations.

Sample Input

2
5 3
545 5

Sample Output

785
5144

Note: we guarantee that any result, intermediate or final, that is produced by the Cow-Bot is not greater than 2\,147\,483\,647.


Comments

There are no comments at the moment.