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

注意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. 登录脚本重构Element

    登录脚本重构Element package com.gubai.selenium; import org.openqa.selenium.By; import org.openqa.selenium. ...

  2. toplink

    TopLink,是位居第一的Java对象关系可持续性体系结构,原署WebGain公司的产品,后被Oracle收购,并重新包装为Oracle AS TopLink.TOPLink为在关系数据库表中存储 ...

  3. Elasticsearch学习(二)————搜索

    Elasticsearch1.query string search1.1.搜索全部// 1. GET http://ip:9200/test/test/_search 结果: { "too ...

  4. js 输出某年某月某日的天数/判断闰年

    console.log(getDays(2017,12,12)); function getDays(year,month,day){ var arr = [31,28,31,30,31,30,31, ...

  5. Java异常归纳

      1.使用Tomcat运行“播报哥架构”出现的两大异常 1.1 监听器异常 详细情况:部署好Maven项目,启动TOMCAT提示如下错误 java.lang.ClassNotFoundExcepti ...

  6. core 中使用 swagger

    引包 代码 public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddMvc().Set ...

  7. vc枚举本机端口信息API

    常用的获取端口信息的函数: GetTcpTableGetExtendedTcpTableGetUdpTableGetExtendedUdpTable GetTcp6Table function Get ...

  8. MySQL-07 日志管理

    学习目标 MySQL日志 二进制日志 错误日志 查询通用日志 慢查询日志 MySQL日志 MySQL日志分为四类,说明如下: 错误日志:记录MySQL服务的启动.运行或者停止时出现的问题. 查询日志: ...

  9. HTML基础(五)表单

    表单的工作原理 简单来说就是客户在浏览器输入信息之后,浏览器将用户在表单中的数据进行打包发送给服务器,服务器接收到之后进行处理,如下图 语法 <form> 表单元素</form> ...

  10. [BZOJ3211]:花神游历各国(小清新线段树)

    题目传送门 题目描述: 花神喜欢步行游历各国,顺便虐爆各地竞赛.花神有一条游览路线,它是线型的,也就是说,所有游历国家呈一条线的形状排列,花神对每个国家都有一个喜欢程度(当然花神并不一定喜欢所有国家) ...