W razie problemów technicznych ze Szkopułem, prosimy o kontakt mailowy pod adresem [email protected].
Jeśli chciałbyś porozmawiać o zadaniach, rozwiązaniach lub problemach technicznych, zapraszamy na serwery Discord. Są one moderowane przez społeczność, ale członkowie zespołu technicznego też są tam aktywni.
Let be a decimal digit different from . We say that an arithmetic expression is a -representation of the integer if a value of this expression is and if it contains only numbers composed of a digit . (All the numbers are of course decimal). The following arithmetical operations are allowed in the expression: addition, subtraction, multiplication and division. Round brackets are allowed too. Division may appear only when a dividend is a multiple of a divisor.
Each of the following expressions is the 5-representation of the number 12:
The length of the -representation is the number of occurrences of digit in the expression. In the example above the first two representations have the length 6, the third - 5, and the forth - 4.
Write a program which:
The first line of the standard input contains digit , is en element of . The second line contains number , . In the following lines there is the series of natural numbers , (for ), one number in each line.
The standard output composes of lines. The -th line should contain:
For the input data:
5 2 12 31168
the correct result is:
4 NIE
Task author: Krzysztof Lorys.