# 穷举法求最接近的真分数

Time Limit: 10000 ms   Case Time Limit: 1000 ms   Memory Limit: 256 MB
Total Submission: 50   Submission Accepted: 14
Judge By Case
Description

Input

Output

Sample Input
 Original Transformed
2 3

Sample Output
 Original Transformed
21845 32767

Hint

100%的数据满足：1≤N＜D≤32767

#include<cstdio>
#include<iostream>
#include<math.h>
#include<vector>

usingnamespace  std;
intgcd(inta,intb)
{
    if(!b)returna;elsereturn  gcd(b,a%b);
}

intmain()
{
    doublen,d;
    cin>>n>>d;

    doublecha=10;
    doublex;
    doubley;

    for(doublei=32767;i>2;i--)
    {
        doublej=i*n/d;
        j=floor(j);
        if(fabs(j/i-n/d)<cha&&((i/d)!=(j/n)))
         {
            cha=fabs(j/i-n/d);
            x=j;
            y=i;
         }
        j=j+1;
        if(fabs(j/i-n/d)<cha&&((i/d)!=(j/n)))
         {
            cha=fabs(j/i-n/d);
            x=j;
            y=i;
         }
         intgg=gcd(x,y);
        x=x/gg;
        y=y/gg;
    }

    cout<<x<<" "<<y<<endl;
    return0;

    }