公倍数之间的情况都是一样的,有循环节。

注意min(a,b)>t的情况和最后一段的处理。C++写可能爆longlong,直接Java搞吧......

import java.io.BufferedInputStream;
import java.math.BigInteger;
import java.util.Scanner; public class Main { public static BigInteger GCD(BigInteger a,BigInteger b)
{
if(b.compareTo(BigInteger.ZERO)==0) return a;
return GCD(b,a.remainder(b));
} public static BigInteger MIN(BigInteger a,BigInteger b)
{
if(a.compareTo(b)>=0) return b;
return a;
} public static void main(String[] args) {
Scanner sc = new Scanner (new BufferedInputStream(System.in)); BigInteger t=sc.nextBigInteger();
BigInteger a=sc.nextBigInteger();
BigInteger b=sc.nextBigInteger(); if(MIN(a,b).compareTo(t)>0)
{
System.out.print("1"+"/"+"1");
}
else{
BigInteger gcd=GCD(a,b);
BigInteger lcm=a.multiply(b).divide(gcd);
BigInteger k=MIN(a,b).subtract(BigInteger.ONE);
BigInteger ans=BigInteger.ZERO;
BigInteger tmp=t.divide(lcm);
ans=k;
if(tmp.compareTo(BigInteger.ZERO)>0)
{
BigInteger u=tmp.subtract(BigInteger.ONE);
ans=ans.add(u.multiply(k.add(BigInteger.ONE)));
ans=ans.add(BigInteger.ONE);
ans=ans.add(MIN(k,t.subtract(lcm.multiply(tmp))));
}
BigInteger fz=ans;
BigInteger fm=t;
BigInteger e=GCD(fz,fm);
fz=fz.divide(e);
fm=fm.divide(e);
System.out.print(fz.toString()+"/"+fm.toString());
}
}
}

CodeForces 592C The Big Race的更多相关文章

  1. codeforces 659D D. Bicycle Race(水题)

    题目链接: D. Bicycle Race time limit per test 1 second memory limit per test 256 megabytes input standar ...

  2. Codeforces Round #438 B. Race Against Time

    Description Have you ever tried to explain to the coordinator, why it is eight hours to the contest ...

  3. CodeForces 48C D - The Race (Fraction,数学)

    每个加油的站可以确定一个alpha的上下界,比如,第i次加油站a[i],前面加了i次油,a[i]*10≤ alpha*i <(a[i]+1)*10. 取最大的下界,取最小的上界,看看两者之间的满 ...

  4. Codeforces Round #131 (Div. 2) E. Relay Race dp

    题目链接: http://codeforces.com/problemset/problem/214/E Relay Race time limit per test4 secondsmemory l ...

  5. Codeforces Round #328 (Div. 2) C. The Big Race 数学.lcm

    C. The Big Race Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/probl ...

  6. Codeforces Round #346 (Div. 2) D Bicycle Race

    D. Bicycle Race 题目链接http://codeforces.com/contest/659/problem/D Description Maria participates in a ...

  7. Codeforces Round #346 (Div. 2) D. Bicycle Race 叉积

    D. Bicycle Race 题目连接: http://www.codeforces.com/contest/659/problem/D Description Maria participates ...

  8. CodeForces 659D Bicycle Race (判断点是否为危险点)

    D - Bicycle Race Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u S ...

  9. Codeforces 659D Bicycle Race【计算几何】

    题目链接: http://codeforces.com/contest/659/problem/D 题意: 若干条直线围城的湖,给定直线的端点,判断多少个转点会有危险?(危险是指直走的的话会掉进水里) ...

随机推荐

  1. 46 Simple Python Exercises-Higher order functions and list comprehensions

    26. Using the higher order function reduce(), write a function max_in_list() that takes a list of nu ...

  2. C# 图片打印杂谈

    日常开头水一下,看了下上次博客,一年零八天了,啧啧,奢侈. 最近这个工作挺满意的,是我想要的发展方向,后续要做机器学习,现在得先把公司之前堆积的问题解决了. 谈人生到此结束,还是说正题吧.(感觉这标题 ...

  3. SQLite – GLOB子句

    SQLite – GLOB子句 .与LIKE不同,GLOB是大小写敏感的,它遵循语法的UNIX指定以下通配符. The asterisk sign (*) The question mark (?) ...

  4. JQuery 获得绝对,相对位置的坐标方法

    获取页面某一元素的绝对X,Y坐标,可以用offset()方法:(body属性设置margin :0;padding:0;) var X = $('#DivID').offset().top; var ...

  5. Android系统固件定制方式

    target_product.mkAndroid系统在构建关于某种产品的固件时,一般会根据特定于该产品的具体target_product.mk来配置生成整个Android系统./target_prod ...

  6. tomcat https协议

    一.tomcat证书 JDK自带的keytool工具来生成证书 1. 在jdk的安装目录\bin\keytool.exe下打开keytool.exe 2. 在命令行中输入以下命令: keytool - ...

  7. billu_b0x靶场刷题

    https://www.vulnhub.com/ 里面有很多安全环境,只要下载相关镜像,在虚拟机上面搭建运行就可以练习对应靶场了. 第一步.信息收集 nmap扫描内网开放80端口的存活主机  nmap ...

  8. JavaEE-04 数据源配置

    学习要点 JNDI 数据库连接池 完成新闻发布系统数据库连接池 JNDI 说明 JNDI(Java Naming and Directory Interface),中文翻译为Java命名与目录接口,是 ...

  9. 微信小程序wx.request请求服务器json数据并渲染到页面

    [原文出自]: https://blog.csdn.net/weixin_39927850/article/details/79766259 微信小程序的数据总不能写死吧,肯定是要结合数据库来做数据更 ...

  10. docker守护式容器运行管理

    docker守护式容器适合运行应用程序和服务 以交互方式进入容器  docker run -it centos /bin/bash 以交互方式进入 并设置镜像名称和运行后的主机名称 退出交互式容器并让 ...