C. The Big Race
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of L meters today.

Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.

While watching previous races the organizers have noticed that Willman can perform onlysteps of length equal to w meters, and Bolt can perform only steps of length equal to bmeters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes).

Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance L.

Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to t (both are included). What is the probability that Willman and Bolt tie again today?

Input

The first line of the input contains three integers tw and b (1 ≤ t, w, b ≤ 5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively.

Output

Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.

The fraction  (p and q are integers, and both p ≥ 0 and q > 0 holds) is called irreducible, if there is no such integer d > 1, that both p and q are divisible by d.

Sample test(s)
input
10 3 2
output
3/10
input
7 1 2
output
3/7
Note

In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack.

题目看了半天啊!!!看懂了算法很好想,可是要用到大数,电脑没装eclipse,gvim写java也是醉醉的,还好最后过的还不算晚。贴一下代码留着以后参考,后面还要仔细整理下BigInteger,BigDecimal

/*
ID: LinKArftc
PROG: Main.java
LANG: JAVA
*/
import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) {
BigInteger t, w, b;
Scanner input = new Scanner(System.in);
while (input.hasNext()) {
t = input.nextBigInteger();
w = input.nextBigInteger();
b = input.nextBigInteger();
BigInteger mi = w.min(b);
BigInteger gcd = w.gcd(b);
BigInteger lcm = w.multiply(b).divide(gcd);
BigInteger ans, cnt, res;
if (lcm.compareTo(t) > 0) {
ans = t.min(w.subtract(BigInteger.ONE).min(b.subtract(BigInteger.ONE)));
} else {
cnt = t.divide(lcm);
res = t.subtract(cnt.multiply(lcm));
ans = cnt.multiply(w.min(b)).add(res.min((w.subtract(BigInteger.ONE)).min(b.subtract(BigInteger.ONE))));
}
gcd = ans.gcd(t);
System.out.println(ans.divide(gcd)+"/"+t.divide(gcd)); }
}
}

再贴一发Python3代码

import sys
import fractions
for line in sys.stdin:
li = line.split()
t = int(li[0])
w = int(li[1])
b = int(li[2])
mi = min(w, b)
Gcd = fractions.gcd(w, b)
Lcm = w * b // Gcd
if Lcm > t:
ans = min(t, w - 1, b - 1)
else:
cnt = t // Lcm
res = t - cnt * Lcm
ans = cnt * min(w, b) + min(res, w - 1, b - 1)
Gcd = fractions.gcd(ans, t)
print("%s/%s" % (ans // Gcd, t // Gcd))

CF#328 (Div. 2) C(大数)的更多相关文章

  1. CF #376 (Div. 2) C. dfs

    1.CF #376 (Div. 2)    C. Socks       dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...

  2. CF #375 (Div. 2) D. bfs

    1.CF #375 (Div. 2)  D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...

  3. CF #374 (Div. 2) D. 贪心,优先队列或set

    1.CF #374 (Div. 2)   D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...

  4. CF #374 (Div. 2) C. Journey dp

    1.CF #374 (Div. 2)    C.  Journey 2.总结:好题,这一道题,WA,MLE,TLE,RE,各种姿势都来了一遍.. 3.题意:有向无环图,找出第1个点到第n个点的一条路径 ...

  5. CF #371 (Div. 2) C、map标记

    1.CF #371 (Div. 2)   C. Sonya and Queries  map应用,也可用trie 2.总结:一开始直接用数组遍历,果断T了一发 题意:t个数,奇变1,偶变0,然后与问的 ...

  6. CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组

    题目链接:CF #365 (Div. 2) D - Mishka and Interesting sum 题意:给出n个数和m个询问,(1 ≤ n, m ≤ 1 000 000) ,问在每个区间里所有 ...

  7. CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组(转)

    转载自:http://www.cnblogs.com/icode-girl/p/5744409.html 题目链接:CF #365 (Div. 2) D - Mishka and Interestin ...

  8. CF#138 div 1 A. Bracket Sequence

    [#138 div 1 A. Bracket Sequence] [原题] A. Bracket Sequence time limit per test 2 seconds memory limit ...

  9. Codeforces Round #328 (Div. 2)

    这场CF,准备充足,回寝室洗了澡,睡了一觉,可结果...   水 A - PawnChess 第一次忘记判断相等时A先走算A赢,hack掉.后来才知道自己的代码写错了(摔 for (int i=1; ...

随机推荐

  1. Assetbundle2

    Assetbundle可以将Prefab封装起来,这是多么方便啊! 而且我也强烈建议大家将Prefab封装成Assetbundle,因为Prefab可以将游戏对象身上带的游戏游戏组件.游戏脚本.材质都 ...

  2. xamdin: 添加小组件报错: render() got an unexpected keyword argument 'renderer'

    查找到 xadmin里面的 dashboard.py文件内render方法,增加一个rdnderer默认参数是None一般路径在 本机虚拟环境\Lib\site-packages\xadmin\vie ...

  3. ubuntu12.04停留在grub界面问题

    修改ubuntu 12.04 停留在grub界面的步骤: 1. 在/etc/default/grub配置文件中, 添加一项GRUB_RECORDFAIL_TIMEOUT: GRUB_TIMEOUT=2 ...

  4. 配置SSH无密钥登陆(三)

    配置SSH无密钥登陆 (1).关闭防火墙 对每个虚拟机进行如下操作:   su    chkconfig  iptables  off 执行之后重启虚拟机:reboot (2).关闭之后,在maste ...

  5. Win10下Pytorch的安装和使用[斗之力三段]

    简介: 看到paper的代码是用Pytorch实现的,试图理解代码,但是看不懂,只能先学一些基础教程来帮助理解.笔记本电脑配置较低,所以安装一个没有CUDA的版本就可以了.安装完之后,就可以跟着教程边 ...

  6. hadoop 环境配置

    HADOOP_HOME E:\tool\eclipse\hadoop-2.7.3 HADOOP_USER_NAME ambari-qa path: %HADOOP_HOME%/bin

  7. Hyperledger04

    代码 'use strict'; var Fabric_Client = require('fabric-client'); var path = require('path'); var util ...

  8. 软工实践Beta冲刺(2/7)

    队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 1.界面的修改与完善 展示GitHub当日代码/文档签入记 ...

  9. http长连接和短连接以及连接的本职

    HTTP长连接和短连接原理浅析 本文主要讲了,http长连接本质是tcp的长连接. 网络通信过程中,建立连接的本质是什么? 连接的本质 建立连接这个词,是从早期的电话系统中来的,那个时候,“建立连接” ...

  10. 玩转VFS(二)

    关于VFS的第一篇中已经太长了 http://www.cnblogs.com/honpey/p/6348914.html 另起一篇: 1)如何在kernel里找到目前文件系统中的根目录: 2) 如何能 ...