鏈接: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 的應用
*/