forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC.cpp
More file actions
95 lines (83 loc) · 2.36 KB
/
C.cpp
File metadata and controls
95 lines (83 loc) · 2.36 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; ++i)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; --i)
#define REP(i,a) for(int i=0,_a=(a); i < _a; ++i)
#define DEBUG(X) { cout << #X << " = " << X << endl; }
#define PR(A,n) { cout << #A << " = "; FOR(_,1,n) cout << A[_] << ' '; cout << endl; }
#define PR0(A,n) { cout << #A << " = "; REP(_,n) cout << A[_] << ' '; cout << endl; }
#define sqr(x) ((x) * (x))
#define ll long long
#define SZ(x) ((int) (x).size())
#define double long double
using namespace std;
#define int long long
const int MN = 200111;
const int MOD = 786433;
const double PI = acos((double) -1.0);
ll buf[10000000],*ptr=buf;
void mul( int n, ll *a, ll *b, ll *c ) {
if ( n<=32 ) {
REP(i,2*n) c[i]=0;
REP(i,n) REP(j,n) c[i+j]+=a[i]*b[j];
REP(i,2*n) c[i]%=MOD;
return;
}
int m=n/2;
ll *s1=ptr; ptr+=n;
ll *s2=ptr; ptr+=n;
ll *s3=ptr; ptr+=n;
ll *aa=ptr; ptr+=m;
ll *bb=ptr; ptr+=m;
REP(i,m) {
aa[i]=a[i]+a[i+m];
bb[i]=b[i]+b[i+m];
if ( aa[i]>=MOD ) aa[i]-=MOD;
if ( bb[i]>=MOD ) bb[i]-=MOD;
}
mul(m,a,b,s1);
mul(m,a+m,b+m,s2);
mul(m,aa,bb,s3);
memcpy(c,s1,n*sizeof(ll));
memcpy(c+n,s2,n*sizeof(ll));
REP(i,n) c[i+m]+=s3[i]-s1[i]-s2[i];
REP(i,2*n) c[i]%=MOD;
ptr-=4*n;
}
ll u[MN], v[MN], f[22][MN];
int sz[22];
#undef int
int main() {
#define int long long
ios :: sync_with_stdio(0); cin.tie(0);
freopen("avl.in", "r", stdin);
freopen("avl.out", "w", stdout);
// initialize
sz[0] = 1;
FOR(i,1,16) sz[i] = sz[i-1] * 2;
f[0][0] = 1;
f[1][1] = 1;
FOR(i,2,15) {
// f[i-1] * f[i-1]
int n;
mul(sz[i-1], f[i-1], f[i-1], u);
mul(sz[i-1], f[i-2], f[i-1], v);
REP(t,sz[i]) if (t) {
f[i][t] = (u[t-1] + v[t-1] * 2) % MOD;
}
}
int n, h;
while (cin >> n >> h) {
if (h < 15) {
cout << (f[h + 1][n] % MOD + MOD) % MOD << endl;
}
else {
ll res = 0;
--n;
REP(i,n+1) {
res += f[h][i] * f[h][n-i] % MOD;
res += (2 * f[h-1][i] * f[h][n-i]) % MOD;
}
cout << (res % MOD + MOD) % MOD << endl;
}
}
}