forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
10007.cpp
57 lines (53 loc) · 860 Bytes
/
10007.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
49
50
51
52
53
54
55
56
57
#include <bits/stdc++.h>
using namespace std;
#define limit 1000000000LL
static int T[305][100] = {0}, len[305];
int main()
{
int i, j, n;
long long int tmp;
T[0][0] = 1;
len[0] = 1;
for (i = 1; i < 305; i++)
{
len[i] = len[i - 1];
for (j = 0; j < len[i]; j++)
{
tmp = (long long int)T[i - 1][j] * (4 * i - 2);
T[i][j] += tmp % limit;
T[i][j + 1] = tmp / limit;
}
if (T[i][len[i]])
{
len[i]++;
}
}
for (i = 1; i < 305; i++)
{
tmp = 0LL;
for (j = len[i] - 1; j >= 0; j--)
{
tmp = tmp * limit + T[i][j];
T[i][j] = (int)(tmp / (i + 1));
tmp %= (i + 1);
}
if (!T[i][len[i] - 1])
{
len[i]--;
}
}
while (scanf("%d", &n) == 1)
{
if (n == 0)
{
break;
}
printf("%d", T[n][len[n] - 1]);
for (i = len[n] - 2; i >= 0; i--)
{
printf("%09d", T[n][i]);
}
printf("\n");
}
return 0;
}