No.1486 Robots
タグ : / 解いたユーザー数 212
作問者 :
tarattata1
/ テスター :
ngtkana
Problem Statement
There are two robots.
When switched on, the first robot repeats the following over and over: "move for $A$ seconds, then stop for $B$ seconds".
When switched on, the second robot repeats the following over and over: "move for $C$ seconds, then stop for $D$ seconds".
Now, the two robots have been switched on at the same time.
Up until $E$ seconds later, for how many seconds (out of the $E$ seconds) are both robots moving at the same time?
Input
$A\ B\ C\ D\ E$
- All inputs are integers
- $1\leqq A,B,C,D\leqq 500$
- $1\leqq E\leqq 10^9$
Output
Print the answer in seconds as an integer, followed by a newline.
Sample
Sample 1
Input
3 2 3 1 10
Output
5
During the period up until 10 seconds after both robots are switched on at the same time,
the first robot moves from 0 seconds to 3 seconds and from 5 seconds to 8 seconds.
The second robot moves from 0 seconds to 3 seconds, from 4 seconds to 7 seconds, and from 8 seconds to 10 seconds.
Both robots move at the same time from 0 seconds to 3 seconds and from 5 seconds to 7 seconds, for a total of 5 seconds.
Sample 2
Input
2 1 3 4 20
Output
6
Sample 3
Input
4 1 8 2 1000000000
Output
700000000
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。