-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuva-10223.cpp
More file actions
57 lines (43 loc) · 1.02 KB
/
uva-10223.cpp
File metadata and controls
57 lines (43 loc) · 1.02 KB
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
49
50
51
52
53
54
55
56
57
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
ULL binomialCoeff(ULL n, ULL r);
int main()
{
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
vector<ULL>CATALAN;
vector<ULL>::iterator p;
ULL n, number;
for (n = 1; ; n++) {
number = binomialCoeff(2 * n, n);
number /= (n + 1);
if (number > 4294967295) {
break;
}
CATALAN.push_back(number);
}
/*
for (n = 0; n < CATALAN.size(); n++) {
printf("%llu\n", CATALAN[n]);
}
*/
while (scanf("%llu", &n) != EOF) {
p = upper_bound(CATALAN.begin(), CATALAN.end(), n);
printf("%d\n", p - CATALAN.begin());
}
return 0;
}
ULL binomialCoeff(ULL n, ULL r)
{
ULL i, res = 1;
/// Because, C(n, r) = C(n, n - r)
if (r > n - r) {
r = n - r;
}
for (i = 0; i < r; i++) {
res *= (n - i);
res /= (i + 1);
}
return res;
}