'commit'
This commit is contained in:
35
TangDou/CSP-J/AcWingTraining/T4/458.cpp
Normal file
35
TangDou/CSP-J/AcWingTraining/T4/458.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
/*
|
||||
由于 L 在100以内,因此可以枚举 A′,B′ 的所有组合,然后判断:
|
||||
(1)、A′,B′ 是否互质;
|
||||
(2)、A′B′ 是否大于等于 AB,并且最小
|
||||
|
||||
时间复杂度:O(L^2 LogL)
|
||||
*/
|
||||
int gcd(int a, int b) {
|
||||
return b ? gcd(b, a % b) : a;
|
||||
}
|
||||
|
||||
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++)
|
||||
if (gcd(i, j) == 1) {
|
||||
double x = i * 1.0 / j; // A' / B'
|
||||
double X = A * 1.0 / B; // A/B
|
||||
|
||||
if (x >= X && x - X < mi) {
|
||||
mi = x - X;
|
||||
a = i, b = j;
|
||||
}
|
||||
}
|
||||
|
||||
cout << a << ' ' << b << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user