No.1987 Sandglass Inconvenience
タグ : / 解いたユーザー数 151
作問者 :
riano
/ テスター :
milkcoffee
Problem Statement
You have $3$ sandglasses, in which all the sand falls in $a$ seconds, $b$ seconds, and $c$ seconds, respectively. Can you use them to measure exactly $X$ seconds? Here, if preparation is needed before exactly $X$ seconds can be measured, you may spend any amount of time on the preparation.
The precise rules are given below.
- Initially, for every sandglass, the sand has completely finished falling.
- A sandglass can be placed with either side up, and the sand keeps falling at a uniform rate as long as there is sand in the upper side.
- You first choose some of the sandglasses and flip them; after that, you may perform operations that change the state of any sandglasses "at the moment when the sand of some sandglass has finished falling". In particular, you may flip other sandglasses whose sand is still falling.
- The time taken by operations is negligible, and you may operate on multiple sandglasses at the same time.
- Having measured exactly $X$ seconds means that the interval from "the time of some operation or of some sand finishing falling" to "the time of another operation or of some sand finishing falling" is exactly $X$ seconds.
Input
$a\ \ b\ \ c$ $X$
- $1\leq a,b,c,X\leq 10^{12}$
- All inputs are integers.
Output
Print Yes if it is possible to measure exactly $X$ seconds, and No if it is impossible.
Print a newline at the end.
Sample
Sample 1
Input
6 10 15 1
Output
Yes
First, flip the $10$-second sandglass and the $15$-second sandglass. After $10$ seconds, the sand of one of them finishes falling, so at this moment flip the $6$-second sandglass. Then, counting from the time the sandglasses were first flipped, the sand of the $15$-second sandglass finishes falling exactly $15$ seconds later, and that of the $6$-second sandglass $16$ seconds later. This interval is exactly $1$ second, so it has been measured.
Sample 2
Input
1000000000000 999999999995 2 5
Output
YesFlip the $1000000000000(=10^{12})$-second sandglass and the $999999999995(=10^{12}-5)$-second sandglass at the same time. The times at which the sand of these $2$ sandglasses finishes falling differ by exactly $5$ seconds, so this measures it. In this case, it takes a long time before $5$ seconds can be measured, but this is allowed.
Sample 3
Input
1000000000000 100000000000 1000000000000 20
Output
No
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。