No.532 Possible or Impossible
Problem Statement
You are given a natural number $N$ and a non-negative integer $M$ not exceeding $N$.
Determine whether the value $M$ can be made by using each of the $N$ numbers from $1$ to $N$ exactly $1$ time, together with the four arithmetic operations and parentheses.
<Notes on the four arithmetic operations>
・Numbers are handled within the range of rational numbers. Therefore, rational numbers may appear during the calculation.
・Division by $0$ is not allowed.
・Since each of the four arithmetic operations determines a new number from $2$ numbers, you cannot multiply by $-1$ during the calculation, as in $-(1+3)\div (-2)=2$.
Input
$N$ $M$
$1\le N\le 50,0\le M\le N$
Output
Print "Possible" if the value $M$ can be made, and "Impossible" if it cannot. Print a newline at the end.
Sample
Sample 1
Input
5 3
Output
Possible
$4\times (5\div 2-1)-3=3$
Sample 2
Input
1 0
Output
Impossible
Since $N=1$, the four arithmetic operations cannot be used. Also, note that $N$ is a natural number, whereas $M$ is a non-negative integer.
Sample 3
Input
10 1
Output
Possible
$8-9-\{(10-7+1)\div 2-4\times 5\}\div (6+3)=1$
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
Pulmn
はむこ