【Codeforces Round 328 (Div 2)C】【lcm 讨论题】The Big Race [1,l]长度距离比赛的平局概率
来源:互联网 发布:上海学声乐 知乎 编辑:程序博客网 时间:2024/04/28 14:00
#include<stdio.h>#include<string.h>#include<ctype.h>#include<math.h>#include<iostream>#include<string>#include<set>#include<map>#include<vector>#include<queue>#include<bitset>#include<algorithm>#include<time.h>using namespace std;void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}#define MS(x,y) memset(x,y,sizeof(x))#define MC(x,y) memcpy(x,y,sizeof(x))#define MP(x,y) make_pair(x,y)#define ls o<<1#define rs o<<1|1typedef long long LL;typedef unsigned long long UL;typedef unsigned int UI;template <class T> inline void gmax(T &a,T b){if(b>a)a=b;}template <class T> inline void gmin(T &a,T b){if(b<a)a=b;}const int N=0,M=0,Z=1e9+7,ms63=1061109567;LL l,a,b;LL x;LL gcd(LL x,LL y){return y==0?x:gcd(y,x%y);}int main(){while(~scanf("%lld%lld%lld",&l,&a,&b)){LL g=gcd(a,b);double lcm_=a/g*(double)b;if(lcm_>6e18)x=min(l,min(a,b)-1);else{LL lcm=a/g*b;LL num=l/lcm;x=num*min(a,b);LL top=num*lcm;LL over=l-top;x+=min(over,min(a,b)-1);}g=gcd(x,l);printf("%lld/%lld\n",x/g,l/g);}return 0;}/*【题意】有两个机器人A与B赛跑。两个机器人的均速都为1m/s然而第一个机器人是每隔a时间单位前进a米,第二个机器人是每隔b时间单位前进b米。我们的比赛距离是[1,l]之间的正整数1<=l,a,b<=5e18现在问你,对于这[1,l]共计l个比赛距离中,两个人不打成平手的概率是多少【类型】讨论lcm【分析】首先,对于lcm(a,b)和其倍数,这些multiple位置上,两只机器人一定是打平的。对于每个multiple+[0,min(a,b)-1]的位置上,两只机器人也一定是打平的。于是我们就求合法范围内所有multiple+[0,min(a,b)-1]的格点数即可。然而要注意1,lcm可能求出会爆int,这种情况下认为只有一个multiple2,对于最大的一个multiple,multiple+[0,min(a,b)-1]要保证不溢出l的范围【时间复杂度&&优化】Olog(l)【数据】123456789012345679 123456789012345679 1234567890123456786 1 7*/
1 0
- 【Codeforces Round 328 (Div 2)C】【lcm 讨论题】The Big Race [1,l]长度距离比赛的平局概率
- Codeforces Round #328 (Div. 2)C. The Big Race(数学gcd && lcm)
- Codeforces Round #328 (Div. 2) C. The Big Race
- Codeforces Round #328 (Div. 2)C. The Big Race
- Codeforces Round #328 (Div. 2)C. The Big Race
- Codeforces Round #328 (Div. 2) C. The Big Race (math)
- Codeforces Round #328 (Div. 2) 592 C. The Big Race
- Codeforces Round #328 (Div. 2)C. The Big Race
- Codeforces 592C The Big Race 【GCD && LCM】
- codeforces#328-C - The Big Race-乘法溢出解决办法之一 + lcm/gcd+数学
- codeforces #328 C. The Big Race
- 【Codeforces Round 340 (Div 2)D】【讨论题】Polyline 三点用最少数量连续不分叉线段连接
- Codeforces Round #146 (Div. 2) C. LCM Challenge
- Codeforces Round #146 (Div. 2) C. LCM Challenge
- Codeforces Round #146 (Div. 2)-C. LCM Challenge
- 【Codeforces Round 333 (Div 2)C】【最短路】The Two Routes 完全图两种双向边的最小最大距离
- Codeforces 592C The Big Race【数学啊】
- 【Codeforces Round 276 (Div 2)C】【讨论】Bits [l,r]范围内第1个数最多数中最小的那个
- base.css
- 三种方法快速获取WordPress当前主题文件夹目录
- Android系统中的Activity简介
- UIDate详解
- 阿里巴巴面试题--Java对象初始化
- 【Codeforces Round 328 (Div 2)C】【lcm 讨论题】The Big Race [1,l]长度距离比赛的平局概率
- lightoj Harmonic Number (II) 1245 (数论)
- 【机器学习】机器学习中的各种相似性、距离度量
- 【Codeforces Round 328 (Div 2)D】【树的直径 树的重心 贪心 两次dfs都找最小编号最远点】Super M 经过树上所有重要点的最小距离
- javascript代码积累
- 计数排序
- Machine Learning week 1 quiz: Linear Regression with One Variable
- 欢迎加入纯净战役服务器
- 更新附加表 `dede_***` 时出错,请检查原因!Unknown column