#CT00000051. Chuông hẹn giờ (Alarm Bells)
Bài tập này chưa được xếp vào lộ trình.
Mục lục đề ⌄
Chuông hẹn giờ (Alarm Bells)
Alarm Bells
Version: Phuoc Hung OJ Extended
Problem Statement
Two bells at an amusement park ring together when the park opens, which is defined as minute . From then on, each bell rings at a fixed interval:
- The first bell rings at minutes .
- The second bell rings at minutes .
Time is measured in integer minutes since opening. The management considers only the interval from minute to minute , including both endpoints.
Count the distinct minutes in when both bells ring simultaneously. Minute counts if it belongs to the interval.
Input
One line contains four integers , in this order:
- : the first bell's ringing interval, in minutes.
- : the second bell's ringing interval, in minutes.
- : the endpoints of the time interval to consider.
Output
Print one integer: the number of minutes in at which both bells ring.
Subtasks
The following general constraints apply to all subtasks: ; .
- Subtask 1 (30%): and .
- Subtask 2 (30%): .
- Subtask 3 (40%): No additional restrictions beyond the general constraints.
Examples
Example 1
Input
4 6 0 30
Output
3
Explanation
The bells ring together at minute and again at minutes . Within , the qualifying minutes are , , and . Minute is greater than , so the answer is .
Example 2
Input
5 7 1 70
Output
2
Explanation
For and , the simultaneous ringing minutes are , , , , and so on. Minute is outside , whereas and are inside it. The answer is .
Example 3
Input
8 12 25 47
Output
0
Explanation
The simultaneous ringing minutes are . Minute is before , and minute is after . Thus there are no qualifying minutes in , and the answer is .
Liên quan
Trong các cuộc thi sau: