Codeforces Round #328 (Div. 2) C. The Big Race 数学.lcm
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
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的更多相关文章
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)
Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...
- Codeforces Round #622 (Div. 2) B. Different Rules(数学)
Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...
- 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 ...
- Codeforces Round #328 (Div. 2) D. Super M
题目链接: http://codeforces.com/contest/592/problem/D 题意: 给你一颗树,树上有一些必须访问的节点,你可以任选一个起点,依次访问所有的必须访问的节点,使总 ...
- 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 ...
- 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 ...
- Codeforces Round #328 (Div. 2) A. PawnChess 暴力
A. PawnChess Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/ ...
- Codeforces Round #328 (Div. 2)
这场CF,准备充足,回寝室洗了澡,睡了一觉,可结果... 水 A - PawnChess 第一次忘记判断相等时A先走算A赢,hack掉.后来才知道自己的代码写错了(摔 for (int i=1; ...
- 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 ...
随机推荐
- 解释一下,在你往浏览器中输入一个URL后都发生了什么,要尽可能详细
这道题目没有所谓的完全的正确答案,这个题目可以让你在任意的一个点深入下去, 只要你对这个点是熟悉的.以下是一个大概流程: 浏览器向DNS服务器查找输入URL对应的IP地址. DNS服务器返回网站的IP ...
- 头痛的ASCII和preg_replace()
说这个之前,大家先看下这条语句: preg_replace("/\<\?\=(\\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\[\]\"\'\$\x7f- ...
- CMake实践(2)
一,本期目标: [~@localhost t2]$ cat README this is README├── CMakeLists.txt├── COPYRIGHT├── doc│ └── hel ...
- Android智能聊天机器人
http://www.tuling123.com/ 注册一个账号,申请一个KEY值.此网站也有文档,可以查看. package com.tulingdemo; import java.te ...
- Windows 窗体最小化和隐藏的区别及恢复
应用程序有托盘图标,窗体最小化或者隐藏窗体时,点击托盘图标需要恢复窗体显示,并且恢复之前的现实状体,正常大小或者最大化显示.例如:最大化显示窗体时,点击最小化按钮,窗体最小化,点击托盘图标将最大化显示 ...
- codeforces 691F Couple Cover 暴力
分析:开一个300w的数组,统计,然后nlogn统计每个值在在序对第一个出现有多少种情况 时间复杂度:O(nlogn) n在3e6数量级 #include<cstdio> #include ...
- Oracle中表结构和表内容复制
处理该问题注意以下几点: 1. 清空表中数据SQL:truncate table table_name; 2.复制表结构SQL:create table table_name1 as select * ...
- IAR编译信息分析
1.怎么设置可以查看单片的内存(消耗)使用状况? IAR的菜单栏 -->Tools -->IDE Options -->Messages -->Show build messa ...
- ASP.NET单点登录(代码)
[p=25, null, left]由于某些原因,在我们的应用中会遇到一个用户只能在一个地方登录的情况,也就是我们通常所说的单点登录.在ASP.NET中实现单点登录其实很简单,下面就把主要的方法和全部 ...
- 四款超棒的jQuery数字化签名插件
在浏览器中,我们有很多方式来绘制生成签名效果,并且有很多很棒很智能的jQuery插件.数字化签名是未来的发展方向,正是这个原因我们这里收集并且推荐了四款超棒的jQuery数字化签名插件,希望大家喜欢! ...