C. The Big Race

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/592/problem/C

Description

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 only steps of length equal to w meters, and Bolt can perform only steps of length equal to b meters. 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 t, w 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 Input

10 3 2

Sample Output

3/10

HINT

题意

终点可以在1-t里面随便选择一个

终点之后都是陷阱,然后有两个人在比赛,一个人一步走w米,一个人一步走b米,谁能不越过终点的情况,走的最远,就算谁赢

然后问你选择平等的概率是多少

题解:

找规律,找规律

对于每个lcm我们可以当成新的一轮是吧,然后每个lcm中,我们可以选择min(w,b)个,作为起点

然后我们搞一搞就好了

这儿唯一遇到的情况就是,当lcm(w,b)> t的时候,这时候就应该输出min(w,b)-1/t

但是我们怎么判断lcm(w,b)>t呢?log(a*1.0) + log(b * 1.0) - log( gcd(a,b)*1.0 )> log (c * 1.0)就好了

代码

#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
long long t,w,b;
long long gcd(long long a,long long b)
{
return b==?a:gcd(b,a%b);
}
long long lcm(long long a,long long b)
{
return a/gcd(a,b)*b;
}
int check(long long a,long long b,long long c)
{
if(log(a*1.0) + log(b * 1.0) - log( gcd(a,b)*1.0 )> log (c * 1.0))
return ;
return ;
} int main()
{
cin>>t>>w>>b;
if(w==b)
{
printf("1/1");
return ;
}
long long ans1,ans2=t;
if(check(w,b,t))
{
ans1 = min(w-,min(b-,t));
}
else
{
long long kkk = lcm(w,b);
long long ggg = t / kkk;
long long Ans1;
if(ggg * kkk + min(w,b) <= t)
Ans1 = (ggg + )* min(w,b) - ;
else
Ans1 = ggg * ( min(w,b) - kkk ) + t;
ans1 = Ans1;
}
printf("%lld/%lld",ans1/gcd(ans1,ans2),ans2/gcd(ans1,ans2));
}

Codeforces Round #328 (Div. 2) C. The Big Race 数学.lcm的更多相关文章

  1. Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)

    Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...

  2. Codeforces Round #622 (Div. 2) B. Different Rules(数学)

    Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...

  3. Codeforces Round #284 (Div. 2)A B C 模拟 数学

    A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #328 (Div. 2) D. Super M

    题目链接: http://codeforces.com/contest/592/problem/D 题意: 给你一颗树,树上有一些必须访问的节点,你可以任选一个起点,依次访问所有的必须访问的节点,使总 ...

  5. Codeforces Round #328 (Div. 2) D. Super M 虚树直径

    D. Super M Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/D ...

  6. Codeforces Round #328 (Div. 2) B. The Monster and the Squirrel 打表数学

    B. The Monster and the Squirrel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/c ...

  7. Codeforces Round #328 (Div. 2) A. PawnChess 暴力

    A. PawnChess Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/ ...

  8. Codeforces Round #328 (Div. 2)

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

  9. Codeforces Round #328 (Div. 2)_B. The Monster and the Squirrel

    B. The Monster and the Squirrel time limit per test 1 second memory limit per test 256 megabytes inp ...

随机推荐

  1. Android下高斯模糊的算法和demo

    采用纯java和RenderScript两种方式来做高斯算法. 也可以用NDK来做,想试试的可以参考: http://stackoverflow.com/questions/2067955/fast- ...

  2. Android-判断当前网络是否可用

    1.声明权限 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 2. ...

  3. Map/Reduce之间的Partitioner接口

    一.Partitioner介绍 Partitioner的作用是对Mapper产生的中间结果进行分片,以便将同一分组的数据交给同一个Reduce处理,它直接影响Reduce阶段的负载均衡(个人理解:就是 ...

  4. awk简单使用『摘.非原创』

    1 awk简介 awk是一种编程语言,用于在linux/unix下对文本和数据进行处理.数据可以来自标准输入.一个或多个文件,或其它命令的输出.它支持用户自定义函数和动态正则表达式等先进功能,是lin ...

  5. 设置layoutControl1 中的 控件的 focus

    设置 layoutControl1 中的layoutControl EnableAutoTabOrder 为 false; this.layoutControl1.ActiveControl = th ...

  6. iBeacon开发

    什么是iBeacons iBeacons是苹果在2013年WWDC上推出一项基于蓝牙4.0(Bluetooth LE | BLE | Bluetooth Smart)的精准微定位技术,当你的手持设备靠 ...

  7. Spark系列(六)Master注册机制和状态改变机制

    各组件的注册流程如下图: 注册机制源码说明: 入口:org.apache.spark.deploy.master文件下的receiveWithLogging方法中的case RegisterAppli ...

  8. 从Search Sort到Join

    发表于<程序员>2015年4月B的一篇文章,在博客归档下.根据杂志社要求,在自己博客发表该文章亦须注明:本文为CSDN编译整理,未经允许不得转载,如需转载请联系market#csdn.ne ...

  9. AHOI2013 Round2 Day1 简要题解

    第一题,好吧这是个dp.(搜素也能在BZOJ上卡过). 第二题,BFS搜索碰到的立方体面数,智硬没有想到... 第三题,其实一看就有思路,但关键是求x坐标不交的矩形对数+y坐标不交的矩形对数 - x, ...

  10. 为了以后愉快的玩耍,Virtualbox安装Ubuntu

    为了以后愉快的玩耍,Virtualbox安装Ubuntu 每次安装虚拟机都是总要折腾一下,毕竟不是特别熟悉,几个小细节总要google半天,为了以后能愉快的玩耍.把这些问题都记录下来,免得再折腾. 此 ...