시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
4 초 (추가 시간 없음) | 512 MB | 8 | 4 | 3 | 50.000% |
Here’s a cool puzzle: Can you write a mathematical expression that evaluates to 113, but only contains common mathematical symbols and four instances of the digit 4?
One possible answer is the following:
\[113 = \frac{\sqrt{4} + (\sqrt{4} + 4!)%}{\sqrt{4}%}\]
Here, ! is the factorial symbol, and % is the percentage symbol, e.g., 11% = 0.11.
Four fours is an arithmetic puzzle/exercise where the goal is to produce a given number using only four fours and common mathematical symbols. For some numbers, this is easy, e.g. 16 can be written as 4 + 4 + 4 + 4. But for others, it isn’t always so, as you may have seen from the example 113 above. As another example, can you produce 2016 using only four fours?
In this problem, you will solve a variation of this puzzle. Given x and y, find a valid mathematical expression that evaluates to y, subject to the following constraints:
If no such expression exists, output IMPOSSIBLE.
The first line of input will contain an integer T, the number of test cases.
The first and only line of each test case will contain two space-separated integers, x and y, as discussed in the problem statement.
Constraints
For each test case output a single line containing a single string.
An expression in postfix notation is evaluated with a stack, initially empty. Then, for each letter from left to right:
At the end of this process, the stack must contain exactly one number, which we define as the result of the evaluation. If the stack doesn’t contain exactly one number, or if an empty stack is popped, then the evaluation fails.
There may be multiple correct answers; any one will be accepted.
4 4 32 3 21 3 21 3 21
xx*xx*+ xxxx+*+ xxxx+*+ xxx**x-x-