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. Python面试315题

    感谢老男孩的武沛齐老师辛苦整理和分享,本文是转自他的博客. 第一部分 Python基础篇(80题) 为什么学习Python? 通过什么途径学习的Python? Python和Java.PHP.C.C# ...

  2. 为什么mysqld启动报错

    在一台ubuntu测试机器上启动一个mysql实例,本来应该是一件很简单的事情, 启动的时候却报错了:   mysqld_safe --defaults-file=/etc/mysql/my3307. ...

  3. CentOS安装Harbor

    CentOS版本:7.4 Harbor版本:1.5.0 Docker版本:1.12.6 Docker Compose版本:1.21.2 一.安装Harbor(http方式,80端口) 1.安装Dock ...

  4. python之time和os模块

    1.time.time()获得的是一个时间戳,距离1970年以来多少秒 2.time.strftime(),按固定格式设置时间 import time print(time.localtime())# ...

  5. HDU 4010 Query on The Trees(动态树LCT)

    Problem Description We have met so many problems on the tree, so today we will have a query problem ...

  6. POJ 3856 deltree(模拟)

    Description You have just run out of disk space and decided to delete some of your directories. Rati ...

  7. RMQ问题+ST算法

    一.相关定义 RMQ问题 求给定区间的最值: 一般题目给定许多询问区间. 常见问题:对于长度为n的数列A,回答若干询问RMQ(A,i,j)(i,j<=n),返回数列A中下标在i,j之间的最小/大 ...

  8. 软工实践 - 第二十五次作业 Beta 冲刺(3/7)

    队名:起床一起肝活队 组长博客:https://www.cnblogs.com/dawnduck/p/10116979.html 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过 ...

  9. 在es中用scroll查询与completableFuture

    一般而言,es返回数据的上限是10000条,如果超过这个数量,就必须使用scroll查询. 所谓scroll查询就类似DBMS中的游标,或者快照吧,利用查询条件,在第一次查询时,在所有的结果上形成了一 ...

  10. windows下Memcached 架设及java应用(转)

    1 Memcache是什么 Memcache是danga.com的一个项目,最早是为 LiveJournal 服务的,目前全世界不少人使用这个缓存项目来构建自己大负载的网站,来分担数据库的压力. 它可 ...