-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1223.cpp
42 lines (30 loc) · 808 Bytes
/
1223.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//1223
#include<iostream>
#include<queue>
using namespace std;
int gcd(const int& a, const int& b) {
return b > 0 ? gcd(b, a % b) : a;
}
int main()
{
int n, k;
cin >> n >> k;
auto cmp = [&](const pair<int, int>& x, const pair<int, int>& y) {
return x.first * y.second > x.second * y.first;
};
priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(cmp)> q(cmp);
for (int j = 2; j <= n; ++j) {
q.emplace(1, j);
}
for (int _ = 1; _ < k; ++_) {
int i = q.top().first;
int j = q.top().second;
q.pop();
if (i + 1 < j) {
while (gcd(i + 1, j) != 1) ++i;
q.emplace(i + 1, j);
}
}
cout << q.top().second - q.top().first << "/" << q.top().second << endl;
return 0;
}