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. 接口测试工具postman(四)导入导出文件

    1.导入json文件 2.单个文件夹导出,文件格式是 json文件 3.所有数据导出,文件格式是 json文件

  2. MySQL☞create语句

    几种常用的建表语句: 1.最简单的建表语句: create table 表名( 列名1 数据类型(长度), 列名2 数据类型(长度), ... ) 2.带主键的建表语句: CREATE TABLE 表 ...

  3. Hyperledger02

    docker 思想 模块化: 集装箱 标准化: 运输标准化, 存储方式标准化,API接口的标准化 安全性: 隔离 docker解决什么问题 devops 我这程序程序没问题啊 系统好卡.哪个程序死循环 ...

  4. python完成简单购物功能

    # # -*- coding: utf8 -*- # # Author:wxq # # date:2017/11/13 # # python 3.6 # 创建一个商品列表: product_lis = ...

  5. 【翻译】ASP.NET Core 文档目录

    微软官方CORE 2.0正式版中文文档已经出来了,地址:https://docs.microsoft.com/zh-cn/aspnet/core/ 简介 入门 创建一个Web应用程序 创建一个Web ...

  6. 【积累】LinqToSql复合查询结果转DataTable数据

    最近的项目用到了大量的复合查询结果用于数据源,绑定到数据控件上. 为了方便,我们把它转换成DataTable的数据源形式.请看下面的示例: 1)思考自己需要的数据,然后组合,因此创建一个新的类: // ...

  7. 【bzoj1951】[Sdoi2010]古代猪文 费马小定理+Lucas定理+中国剩余定理

    题目描述 求  $g^{\sum\limits_{k|n}C_{n}^{\frac nk}}\mod 999911659$ 输入 有且仅有一行:两个数N.G,用一个空格分开. 输出 有且仅有一行:一个 ...

  8. 前端工程师必须要知道的SEO技巧(1):rel=nofollow的使用

    前提:最近我在找工作,想面试一些关于前端的工作,被问到了一些关于SEO优化的问题.我深深的感觉我所回答的太过于表面,没有深入.所以,又把SEO的内容看了一遍.自己总结如下:有的是看的其他博友的贴子,发 ...

  9. hdu 2199 Can you solve this equation? (二分法)

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  10. 一张图彻底搞懂JavaScript的==运算

    一张图彻底搞懂JavaScript的==运算 来源 https://zhuanlan.zhihu.com/p/21650547 PS:最后,把图改了一下,仅供娱乐 : ) 大家知道,==是JavaSc ...