Codeforces Round #328 (Div. 2) C. The Big Race 数学.lcm

时间:2022-09-23 09:25:56

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.

Codeforces Round #328 (Div. 2) C. The Big Race 数学.lcm

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 Codeforces Round #328 (Div. 2) C. The Big Race 数学.lcm. Follow the format of the samples output.

The fraction Codeforces Round #328 (Div. 2) C. The Big Race 数学.lcm (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 &num;368 &lpar;Div&period; 2&rpar; C&period; Pythagorean Triples(数学)

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

  2. Codeforces Round &num;622 &lpar;Div&period; 2&rpar; B&period; Different Rules(数学)

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

  3. Codeforces Round &num;284 &lpar;Div&period; 2&rpar;A B C 模拟 数学

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

  4. Codeforces Round &num;328 &lpar;Div&period; 2&rpar; D&period; Super M

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

  5. Codeforces Round &num;328 &lpar;Div&period; 2&rpar; D&period; Super M 虚树直径

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

  6. Codeforces Round &num;328 &lpar;Div&period; 2&rpar; B&period; 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 &num;328 &lpar;Div&period; 2&rpar; A&period; PawnChess 暴力

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

  8. Codeforces Round &num;328 &lpar;Div&period; 2&rpar;

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

  9. Codeforces Round &num;328 &lpar;Div&period; 2&rpar;&lowbar;B&period; 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. Python 面向对象2

    静态方法 静态方法相当于函数,可以不创建对象直接引用 如果在类里面用静态方法,相当于函数,可以不创建对象,直接是用类里面的方法,你就当它是函数. 静态方法名义上归类管理,实际上静态方法访问不了类或实例 ...

  2. zookeeper 安装与配置

    (1) 下载ZooKeeper,建议选择稳定版,即stable的. [root@bonnie1 ~]# cd /usr/local [root@bonnie1 local]# wget http:// ...

  3. 一个简单的scrapy爬虫抓取豆瓣刘亦菲的图片地址

    一.第一步是创建一个scrapy项目 sh-3.2# scrapy startproject liuyifeiImage sh-3.2# chmod -R 777 liuyifeiImage/ 二.分 ...

  4. 安卓UDP通信

    功能: 实现了单次一发一收: import java.net.*; import java.io.*; public class udpRecv { /* * 创建UDP传输的接收端 * 1.建立ud ...

  5. 快速理解web语义化

    什么是Web语义化 Web语义化是指使用恰当语义的html标签.class类名等内容,让页面具有良好的结构与含义,从而让人和机器都能快速理解网页内容.语义化的web页面一方面可以让机器在更少的人类干预 ...

  6. 基于SPA的网页授权流程&lpar;微信OAuth2&rpar;

    先说传统MVC网站的网页授权流程. 1.用户发起了某个需要登录执行的操作 2.收集AppId等信息重定向到微信服务器 3.微信服务器回调到网站某个Controller的Action 4.在此Actio ...

  7. alias重命名命令

    升级了openssh后,发现ctrl+l忽然无法清屏了. 如果需要清屏的话,就得执行clear,但我更喜欢简单粗暴的做法,于是想起alias命令 方式一: 如果只想在当前终端生效(exit该窗口终端后 ...

  8. nginx-ngx&lowbar;http&lowbar;random&lowbar;index&lowbar;module

    模块简介:在收到以"/"为结尾的请求时,在对应的目录下随机选择一个文件作为index文件. 模块类型:常用标准http模块 使用实例: location /privacy_poli ...

  9. 常用数据库驱动名称以及URL

    oracle: 驱动类的名字:oracle.jdbc.driver.OracleDriver URL:jdbc:oracle:thin:@dbip:port:databasename Mysql: 驱 ...

  10. install ros-indigo-tf2

    sudo apt-get install ros-indigo-tf2