链接:https://ac.nowcoder.com/acm/contest/1109/I
来源:2019牛客国庆集训派对day4
- 题目描述
- 输入描述:
The input contains zero or more test cases and is terminated by end-of-file.
Each test case contains two integers n, m.
The number of tests cases does not exceed .- 输出描述:
For each case, output a fraction p/q which denotes the result.- 输入
1 1
1 2- 输出
1/2
1/4- 备注:
For the first sample, maximizes the function.
题意
最大化
思路
,我们设
根据题意可知此方程式一定有解,那么就是
有解,所以
,得到
,我们找出两个点
,这两个点之间的距离为
,我们需要找到的答案就是
到这些点的距离哪一个最近并且是最大的。由上述分析可知
到上面两个点的中点才可以最大化
。即
。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Max_n=1e6+10;
int gcd(int a,int b){
return b==0?a:gcd(b,a%b);
}
ll lcm(int a,int b){
return 1ll*a*b/gcd(a,b);
}
int main(){
int n,m;
while(~scanf("%d%d",&n,&m)){
printf("%d/%lld\n",1,2*lcm(n,m));
}
return 0;
}
/**
* Copyright(c)
* All rights reserved.
* Author : Max_n
* Date : 2019-10-05-16.42.31
* Description : exgcd 的应用
*/