显示代码纯文本
#include<iostream>
#include<cstdio>
using namespace std;
int read()
{
int x,f=1;
char ch;
while(ch=getchar(),!isdigit(ch))if(ch=='-')f=-1;
x=ch-48;
while(ch=getchar(),isdigit(ch))x=x*10+ch-48;
return x*f;
}
void write(int x)
{
if(x<0)putchar('-'),x=-x;
int cnt=0;char ch[50];
while(ch[++cnt]=x%10+48,x/=10);
while(putchar(ch[cnt]),--cnt);
putchar(' ');
}
double _abs(double x)
{
if(x<0)return -x;
else return x;
}
int gcd(int x,int y)
{
int z=x%y;
while(z)
{
x=y;y=z;z=x%y;
}
return y;
}
int main()
{
freopen("ratio.in","r",stdin);
freopen("ratio.out","w",stdout);
int n=read(),m=read(),l=read(),A,B;double ans=0x7f7f7f7f;
bool f=0;
double a=(double)n/m;
for(int i=1;i<=l;i++)
{
for(int j=1;j<=l;j++)
{
double b=(double)i/j;
if(b<a)continue;//注意b要大于a
if(b-a<ans)
{
ans=_abs(b-a);
A=i;
B=j;
}
}
}
int G=gcd(A,B);
write(A/G),write(B/G);
// system("pause");
}