2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛:I— Strange Optimization

题目链接:传送门

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.


解题思路:f(t) = 1/Icm(n,m)*2

|i/n-j/m|所能表示的最小值为1/Icm(n,m),令其为p,当t>=p,f(t)=0。当t

#include   
#include   
#include   
#include   
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;  
typedef  __int64 ll;
const int N = 100100;
const int M = 20;
const int INF = 0x3fffffff;

int gcd( int a , int b )
{
	if( b == 0 ) return a;
	else return gcd( b , a%b );
}

int main()
{
	ll n,m;
	while( ~scanf("%I64d%I64d",&n,&m) ){
		ll p = n/gcd(n,m)*m*2;
		printf("%d/%I64d\n",1,p);
	}
	return 0;
}



你可能感兴趣的:(简单数学,数学题)