蔡悠然 • 2个月前
#include <bits/stdc++.h>
using namespace std;
double a, b, c;
double mmin = 9999999.0;
double kkk;
int ans1, ans2;
int gcd(int x, int y)
{
if(y == 0) return x;
return gcd(y, x % y);
}
signed main()
{
scanf("%lf%lf%lf", &a, &b, &c);
kkk = (double)a * 1.0 / (b * 1.0);
for(int i = 1; i <= c; ++i)
{
for(int j = 1; j <= c; ++j)
{
if(gcd(i, j) == 1)
{
if((double)i * 1.0 / (j * 1.0) >= kkk)
if(mmin > (double)abs(kkk * 1.0 - i * 1.0 / (j * 1.0)))
{
mmin = (double)abs(kkk * 1.0 - i * 1.0 / (j * 1.0));
ans1 = i;
ans2 = j;
}
}
}
}
printf("%d %d", ans1, ans2);
return 0;
}
评论: