XTU 1268 Strange Optimization 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛(湖南)

Strange Optimization

 
Accepted : 65   Submit : 286
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


解题思路:在比赛的时候并全会写,只是推出了一部分,抱着侥幸的心理交了一发,运气包票的过了。。。。。有大神说用裴蜀定理可以推算出来,最后推算出来的就是答案。。。可我这渣渣还是不懂,所以只有简单的代码了。。。

代码如下:

#include 
#include 
#include 
#define LL __int64
using namespace std;
LL gcd(LL a,LL b)///求最大公约数
{
    return !b ? a : gcd(b,a%b);
}
int main()
{
    LL n,m;
    while(scanf("%I64d %I64d",&n,&m)!=EOF)
    {
        LL s=gcd(n,m);
        printf("1/%I64d\n",n/s*m*2);
    }
    return 0;
}


你可能感兴趣的:(OJ)