-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path078.cpp
More file actions
41 lines (37 loc) · 708 Bytes
/
Copy path078.cpp
File metadata and controls
41 lines (37 loc) · 708 Bytes
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
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ll f, p;
cin >> f >> p;
if (f <= 0 || p < 0) {
cout << 0 << endl;
return 0;
}
if (p >= f) {
cout << f << endl;
return 0;
}
ll d = f - p;
ll cur = 0;
for (int i = 0; i < 4; ++i) {
ll delta = cur + 1;
ll low = (cur * f / p) + 1;
ll high = (delta * f / p);
ll chosen = -1;
for (ll pk = low; pk <= high; ++pk) {
ll temp = pk * d;
ll q = temp / f;
ll nextk = pk - 1 - q;
if (nextk == cur) {
chosen = pk;
break;
}
}
assert(chosen != -1);
cur = chosen;
}
ll ans = f + cur * d;
cout << ans << endl;
return 0;
}