#GL0000303. Vòng tròn các nhà hàng (The Beatles)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Vòng tròn các nhà hàng (The Beatles)
The Beatles
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A circular road passes through cities numbered from to . Consecutive cities are one kilometer apart. Exactly restaurants are located in cities .
Sergey starts in a city and always travels in one fixed direction around the circle. He stops after every kilometers, where is a positive integer. His trip ends when a stop brings him back to .
He has forgotten both and , but remembers that the shortest distance from to a restaurant was kilometers, and the shortest distance from his first stopping city to a restaurant was kilometers. Both clockwise and counterclockwise distances are allowed when measuring distance to a restaurant.
Determine the minimum and maximum possible numbers of stops until he returns to . Include the final stop at but do not count the initial starting position.
Input
The first line contains : the number of restaurants and the distance in kilometers between consecutive restaurants.
The second line contains : the shortest distances to a restaurant from the starting and first stopping cities.
Output
Print two integers on one line: the minimum and maximum possible numbers of stops.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Example 1
Input
2 3
1 1
Output
1 6
Explanation
Restaurants are in cities and ; possible starting and first-stop cities are . Returning on the first stop is possible, so the minimum is . A step of kilometer also fits the observations and needs all stops before returning.
Example 2
Input
3 2
0 0
Output
1 3
Explanation
Since , both observed cities contain restaurants. The step is a multiple of on a circle of length . Returning in stop is possible; traversing all three restaurant locations needs stops.
Example 3
Input
1 10
5 3
Output
5 5
Explanation
There is one restaurant in city . The starting city is ; the first stop can be or , giving a positive step congruent to or modulo . Both need stops to return.