#P1236. 算24点

算24点

Description

Decades ago, a number game became popular worldwide and is still enjoyed today. In China, we call this game "24 Game". As a player, you are given 4 natural numbers between 11 and 99 as operands. Your task is to perform arithmetic operations on these 4 operands so that the result equals 2424.

You may use only the operations +,-,*,\verb!+!, \verb!-!, \verb!*!, and /\verb!/!. You may also use ()\verb!()! to change the order of operations. Note: all intermediate results must be integers, so some divisions are not allowed (for example, (2×2)/4(2\times 2)/4 is valid, while 2×(2/4)2\times (2/4) is invalid). Here is a concrete example of the game:

If the 4 operands are 11, 22, 33, and 77, then one possible answer is 1+2+3×7=241+2+3\times 7=24.

Input Format

A single line containing four natural numbers between 11 and 99 (inclusive).

Output Format

If a solution exists, output any one solution. The output consists of three lines, each describing one computation step.

  • The first line is two input numbers, an operator, and the result after the operation.
  • The second line is the result from the first line combined with one remaining input number, an operator, and the new result, or the result of applying an operator to the other two input numbers.
  • The third line combines the previous result, the second line’s result or the remaining number, an operator, and =24\verb!=24!. If two operands are different, output the larger one first.

If there is no solution, output No answer!.

If multiple valid solutions exist, output any one of them.

Note: all operation results must be positive integers.

1 2 3 7

2+1=3
7*3=21
21+3=24

Hint

Thanks to chenyy for the special judge.


upd 2022.8.1\text{upd 2022.8.1}: Added a new set of hack testdata.

Translated by ChatGPT 5