CF1142A.The Beatles
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Recently a Golden Circle of Beetlovers was found in Byteland. It is a circle route going through n⋅k cities. The cities are numerated from 1 to n⋅k, the distance between the neighboring cities is exactly 1 km.
Sergey does not like beetles, he loves burgers. Fortunately for him, there are n fast food restaurants on the circle, they are located in the 1-st, the (k+1)-st, the (2k+1)-st, and so on, the ((n−1)k+1)-st cities, i.e. the distance between the neighboring cities with fast food restaurants is k km.
Sergey began his journey at some city s and traveled along the circle, making stops at cities each l km (l>0), until he stopped in s once again. Sergey then forgot numbers s and l, but he remembers that the distance from the city s to the nearest fast food restaurant was a km, and the distance from the city he stopped at after traveling the first l km from s to the nearest fast food restaurant was b km. Sergey always traveled in the same direction along the circle, but when he calculated distances to the restaurants, he considered both directions.
Now Sergey is interested in two integers. The first integer x is the minimum number of stops (excluding the first) Sergey could have done before returning to s. The second integer y is the maximum number of stops (excluding the first) Sergey could have done before returning to s.
最近,人们在比特兰发现了一个“甲虫爱好者黄金圈”。它是一条经过 n⋅k 座城市的环形路线。这些城市编号从 1 到 n⋅k,相邻城市之间的距离恰好为 1 千米。
谢尔盖不喜欢甲虫,他钟爱汉堡。幸运的是,圆周上分布着 n 家快餐店,分别位于第 1、第 (k+1)、第 (2k+1)、……、第 ((n−1)k+1) 座城市,即相邻快餐店所在城市之间的距离为 k 千米。
谢尔盖从某座城市 s 出发,沿该圆周旅行,每前进 l 千米(l>0)便在一座城市停下,直到他再次回到起点 s 为止。随后,谢尔盖忘记了 s 和 l 的具体取值,但他记得:从起点城市 s 到最近一家快餐店的距离为 a 千米;而从他出发后前行 l 千米所到达的城市(即第一个停靠点)到最近一家快餐店的距离为 b 千米。谢尔盖始终沿圆周朝同一方向行进,但在计算到快餐店的距离时,他考虑了两个方向(即取顺时针与逆时针距离中的较小值)。
现在,谢尔盖关心两个整数:第一个整数 x 表示他在返回 s 之前(不包括起点)可能的最少停靠次数;第二个整数 y 表示他在返回 s 之前(不包括起点)可能的最多停靠次数。
输入格式
The first line contains two integers n and k (1≤n,k≤100000) — the number of fast food restaurants on the circle and the distance between the neighboring restaurants, respectively.
The second line contains two integers a and b (0≤a,b≤2k) — the distances to the nearest fast food restaurants from the initial city and from the city Sergey made the first stop at, respectively.
第一行包含两个整数 n 和 k(1≤n,k≤100000)—— 分别表示圆周上快餐店的数量以及相邻快餐店之间的距离。
第二行包含两个整数 a 和 b(0≤a,b≤2k)—— 分别表示初始城市到最近的快餐店的距离,以及谢尔盖第一次停靠的城市到最近的快餐店的距离。
输出格式
Print the two integers x and y.
输出两个整数 x 和 y。
输入输出样例
输入#1
2 3 1 1
输出#1
1 6
输入#2
3 2 0 0
输出#2
1 3
输入#3
1 10 5 3
输出#3
5 5
说明/提示
In the first example the restaurants are located in the cities 1 and 4, the initial city s could be 2, 3, 5, or 6. The next city Sergey stopped at could also be at cities 2,3,5,6. Let's loop through all possible combinations of these cities. If both s and the city of the first stop are at the city 2 (for example, l=6), then Sergey is at s after the first stop already, so x=1. In other pairs Sergey needs 1,2,3, or 6 stops to return to s, so y=6.
In the second example Sergey was at cities with fast food restaurant both initially and after the first stop, so l is 2, 4, or 6. Thus x=1, y=3.
In the third example there is only one restaurant, so the possible locations of s and the first stop are: (6,8) and (6,4). For the first option l=2, for the second l=8. In both cases Sergey needs x=y=5 stops to go to s.
在第一个例子中,餐厅位于城市 1 和 4,初始城市 s 可以是 2、3、5 或 6。谢尔盖第一次停留的城市也可能是 2、3、5 或 6。我们遍历所有这些城市的可能组合。若 s 与第一次停留的城市均为城市 2(例如,l=6),则谢尔盖在第一次停留后已回到 s,因此 x=1。对于其余组合,谢尔盖需分别经过 1、2、3 或 6 次停留才能返回 s,故 y=6。
在第二个例子中,谢尔盖初始所在城市及第一次停留的城市均设有快餐店,因此 l 的可能取值为 2、4 或 6。于是 x=1,y=3。
在第三个例子中,仅存在一家餐厅,因此 s 与第一次停留城市的可能组合为:(6,8) 和 (6,4)。对第一种情况,l=2;对第二种情况,l=8。在这两种情况下,谢尔盖均需 x=y=5 次停留才能返回 s。
输入解题思路,AI测评打分。不知道怎么写?