这个写法有个坑就是如果最大公约数是1是最小公倍数必然是两个数乘积,可能爆 long long,所以取巧处理了一下
其他处理方法:1、double存储点击打开链接
2、点击打开链接
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <bitset>
using namespace std;
#define LL unsigned long long
LL gcd(LL a , LL b)
{
if(a%b == 0) return b;
else return gcd(b , a%b);
}
int main()
{
LL t , b , w;
while(scanf("%I64d %I64d %I64d" , &t , &w , &b) != EOF)
{
if(w == b)
{
printf("1/1\n");
continue;
}
// LL ans = 0;
if(w > b) swap(w , b);
LL minn = min(w , b);
minn -- ;
LL res = gcd(b , w);
LL lcd = w / res * b ;
LL num = t / lcd;
LL maxx = min(t - num * lcd , minn);
if(w / res * b - t > 0 && w / res * b - 1e18 > 0) {num = 0 ; goto tt;}
if(w == 1 || b == 1) maxx += (num - 1) * minn;
else maxx += (num) * minn;
tt: num += maxx;
LL tmp = gcd(num , t);
printf("%I64d/%I64d\n" , num / tmp , t / tmp );
}
return 0;
}
/*
4000000000000000000 9999999999999997 99999999999999999
2499999999999999/1000000000000000000
19999999999999993
*/