-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAmphibian Escape.cpp
39 lines (31 loc) Β· 960 Bytes
/
Amphibian Escape.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
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) {
long long N, K, H;
cin >> N >> K >> H;
long long count = 0;
// Iterate over possible values of A
for (long long A = 1; A <= N; ++A) {
if (A >= H) {
// If A itself is greater than or equal to H, any B will work
count += N;
} else {
// Calculate maximum B such that the frog escapes
long long maxB = ((K * A) - H) / (K - 1);
// Include all valid Bs that meet the condition
// maxB should be greater than or equal to 1 and within the range [1, N]
if (maxB > 0) {
count += min(maxB, N);
}
}
}
cout << count << endl;
}
return 0;
}