cf592c 数学 超范围大数

题目链接

这个写法有个坑就是如果最大公约数是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
*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值