-
Notifications
You must be signed in to change notification settings - Fork 0
/
PRUBALL.cpp
48 lines (41 loc) · 893 Bytes
/
PRUBALL.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
43
44
45
46
47
48
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define lld long long int
lld binomialCoeff(int x, int n)
{
lld sum = 0, term = 1;
for (int i = 1; i <= n; ++i) {
term *= x - i + 1;
term /= i;
sum += term;
}
return sum;
}
int minTrials(int n, int k)
{
int low = 1, high = k;
while (low < high) {
int mid = (low + high) / 2;
if (binomialCoeff(mid, n) < k)
low = mid + 1;
else
high = mid;
}
return low;
}
int main() {
// your code goes here
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lld t;
cin>>t;
while(t--)
{
int a,n,k;
cin>>a>>n>>k;
cout<<a<<" "<<minTrials(n, k)<<'\n';
}
}