You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
/*
|
|
|
|
|
由于 L 在100以内,因此可以枚举 A′,B′ 的所有组合,然后判断:
|
|
|
|
|
(1)、A′,B′ 是否互质;
|
|
|
|
|
(2)、A′B′ 是否大于等于 AB,并且最小
|
|
|
|
|
|
|
|
|
|
优化:
|
|
|
|
|
由于我们是从小到大枚举的每一个(A',B'),所以,如果gcd(A',B')>1时,那么,一定在前面枚举过(A'/d,B'/d).这两组的比值是相同的,面
|
|
|
|
|
后面我们的判断取最小的条件是x-X<mi,这组后来的(A',B')肯定是无法覆盖掉前面的$A'/d,B'/d$,也就是最终结果中保存的就是互质的一组数据的比例
|
|
|
|
|
,由此,可以优化掉一个logL的时间复杂度,从而将O(L^2 LogL)优化为 :O(L^2)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
int A, B, L;
|
|
|
|
|
cin >> A >> B >> L;
|
|
|
|
|
|
|
|
|
|
int a, b;
|
|
|
|
|
double mi = 1e9;
|
|
|
|
|
for (int i = 1; i <= L; i++)
|
|
|
|
|
for (int j = 1; j <= L; j++) {
|
|
|
|
|
double x = i * 1.0 / j;
|
|
|
|
|
double X = A * 1.0 / B;
|
|
|
|
|
|
|
|
|
|
if (x >= X && x - X < mi) {
|
|
|
|
|
mi = x - X;
|
|
|
|
|
a = i, b = j;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cout << a << ' ' << b << endl;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|