Strange Optimization(扩展欧几里得)

Strange Optimization

Accepted : 67 Submit : 289
Time Limit : 1000 MS Memory Limit : 65536 KB

 

Strange Optimization

Bobo is facing a strange optimization problem. Given n,m , he is going to find a real number α such that f(12+α) is maximized, where f(t)=mini,jZ|injm+t| . Help him!

Note: It can be proved that the result is always rational.

Input

The input contains zero or more test cases and is terminated by end-of-file.

Each test case contains two integers n,m .

  • 1n,m109
  • The number of tests cases does not exceed 104 .

Output

For each case, output a fraction p/q which denotes the result.

Sample Input

1 1
1 2

Sample Output

1/2
1/4

Note

For the first sample, α=0 maximizes the function

 

 

//题意还是很好懂的,只要明白扩展欧几里得原理,这题很简单,i/n - j/m 可以化为 ( mi - nj ) / ( n * m )

因为 i,j 为整数所以等于  k*gcd(n,m)/(n*m)

所以 f(t)的最大值为 1 / ( Lcm(n,m)*2 )

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <algorithm>
 5 using namespace std;
 6 #define LL long long
 7 
 8 LL gcd(LL a,LL b)
 9 {
10     return b==0?a:gcd(b,a%b);
11 }
12 
13 int main()
14 {
15     LL n,m;
16     while (scanf("%I64d%I64d",&n,&m)!=EOF)
17     {
18         LL p = gcd(n,m);
19         LL q = n*m*2;
20         LL yue = gcd(p,q);
21         printf("%I64d/%I64d\n",p/yue,q/yue);
22     }
23     return 0;
24 }
View Code

 

转载于:https://www.cnblogs.com/haoabcd2010/p/6861733.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值