The MTM Machine |
The MTM is one of the first digital machines ever designed. The aim of the machine is to process positive integer numbers, but due to the primitive nature of the machine only some numbers are accepted for processing; such numbers are called acceptable. When a number is accepted by MTM, the machine outputs another number, according to the rules stated below. When a number is not accepted, the machine simply outputs NOT ACCEPTABLE.
A number is a non empty string of decimal digits. Given two numbers N and M, when we write NM we mean the number formed by the digits of N followed immediately by the digits of M. For example, if N is 856 and M is 112 then NM is 856112. For any number X, the associate of X is the number X2X. For example, the associate of 78 is 78278.
We say that a number X produces a number Y, if number X is acceptable and when given as input to the machine MTM, the number returned by the machine is Y.
The behaviour of the MTM machine is governed by the following rules:
Your task here is to write a program that simulates the MTM machine.
You may assume that the largest number output by the machine has at most 1000 digits.
20 22 42 32 33289 0
NOT ACCEPTABLE 2 NOT ACCEPTABLE NOT ACCEPTABLE 89289289289