zoukankan      html  css  js  c++  java
  • CodeForces 592C The Big Race

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

    注意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());
            }
        }
    } 
  • 相关阅读:
    ajax中文乱码问题的总结
    JQuery中$.ajax()方法参数详解
    Jquery的parent和parents(找到某一特定的祖先元素)
    div节点的操作(添加,删除,替换,克隆)
    js 刷新页面
    ADO.NET 体系结构
    数据访问技术介绍
    WebForm页面数据绑定总结
    sql 智能提示
    用TTTAttributedLabel创建变化丰富的UILabel
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5470217.html
Copyright © 2011-2022 走看看