cf592c 数学 超范围大数

来源:互联网 发布:手机淘宝闲置怎么用 编辑:程序博客网 时间:2024/06/06 09:50

题目链接

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


0 0
原创粉丝点击