Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of L meters today.
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While watching previous races the organizers have noticed that Willman can perform only steps of length equal to w meters, and Bolt can perform only steps of length equal to b meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes).
Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance L.
Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to t (both are included). What is the probability that Willman and Bolt tie again today?
Input
The first line of the input contains three integers t, w and b (1 ≤ t, w, b ≤ 5·1018) — the maximum possible length of the racetrack, the length of Willman’s steps and the length of Bolt’s steps respectively.
Output
Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.
The fraction ( p and q are integers, and both p ≥ 0 and q > 0 holds) is called irreducible, if there is no such integer d > 1, that both p and q are divisible by d.
Examples
Input
10 3 2
Output
3/10
Input
7 1 2
Output
3/7
Note
In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack.
题意:
两个人,起点为0(我是看成段区间,起点那就是0),跑道距离L,1≤L≤t。
第一个人一步走w,第二个人一步走b,走单位1长度速度相同。
但是不能越过跑道长度,如果最终停止点相同则平均,求跑道距离在
[
1
,
t
]
[1,t]
[1,t]内随机时多大可能会平局。
思路:
可以发现,当跑道长度为
l
c
m
(
w
,
b
)
lcm(w,b)
lcm(w,b)的倍数时,两人会同时到达这个点,此时肯定是平局。然后接下来min(w,b)-1长度两人都走不了,跑道加上这个长度还是平局。所以直接统计t内有多少个
l
c
m
(
w
,
b
)
lcm(w,b)
lcm(w,b)倍数就可以了。
不过注意0要剔除,因为题目范围不包括0。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
__int128 gcd(__int128 n,__int128 m) {
return m == 0 ? n : gcd(m,n % m);
}
int main() {
ull t,w,b;scanf("%llu%llu%llu",&t,&w,&b);
__int128 Lcm = w / gcd(w,b) * b;
ull ans = 0;
ull lcm;
if(Lcm > t) {
ans = min(t,min(w,b) - 1);
} else {
lcm = (ull)Lcm;
ans += (t / lcm + 1) * min(w,b) - 1;
ull mx = t / lcm * lcm + min(w,b) - 1; //可能对应的最后位置
if(t <= mx) {
ans -= mx - t;
}
}
ull tmp = gcd(ans,t);
ans /= tmp;
t /= tmp;
printf("%llu/%llu\n",ans,t);
return 0;
}