Codeforces 300D Painting Square (FFT)
2016-03-15 20:25
441 查看
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <queue> #include <set> #include <ctime> #include <cstdlib> #include <tr1/unordered_map> using namespace std; using namespace std::tr1; #define N 60020 #define LL long long #define ls (i << 1) #define rs (ls | 1) #define md ((ll + rr) >> 1) #define lson ll, md, ls #define rson md + 1, rr, rs #define inf 0x3f3f3f3f #define K 3 const int P = 7340033; const int pRoot = 3; int rev ; int dp[33] ; int t ; int qpow(int x, int k) { int ret = 1; while(k) { if(k & 1) ret = 1LL * ret * x % P; k >>= 1; x = 1LL * x * x % P; } return ret; } void change(int y[], int len) { for(int i = 1; i < len; ++i) { rev[i] = (rev[i>>1] >> 1) + ((i & 1) * (len >> 1)); if(i < rev[i]) swap(y[i], y[rev[i]]); } } void FFT(int y[], int len, int on) { change(y, len); for(int h = 2; h <= len; h <<= 1) { int wn = qpow(pRoot, (P - 1) / h); if(on == -1) wn = qpow(wn, P - 2); for(int j = 0; j < len; j += h) { int w = 1; for(int k = j; k < j + h / 2; ++k) { int u = y[k]; int t = 1LL * y[k+h/2] * w % P; y[k] = u + t; if(y[k] >= P) y[k] -= P; y[k+h/2] = u + P - t; if(y[k+h/2] >= P) y[k+h/2] -= P; w = 1LL * w * wn % P; } } } if(on == -1) { int inv = qpow(len, P - 2); for(int i = 0; i < len; ++i) { y[i] = 1LL * y[i] * inv % P; } } } void calc(int a[], int b[], int len) { len *= 2; for(int i = 0; i < len; ++i) { if(i < len / 2) a[i] = b[i]; else a[i] = 0; } FFT(a, len, 1); for(int i = 0; i < len; ++i) a[i] = 1LL * a[i] * a[i] % P; FFT(a, len, -1); } void init() { dp[0][0] = 1; for(int i = 1; i < 33; ++i) { calc(dp[i], dp[i-1], 1 << 10); calc(dp[i], dp[i], 1 << 10); for(int j = (1 << 10) - 1; j > 0; --j) { dp[i][j] = dp[i][j-1]; } dp[i][0] = 1; } } int main() { init(); int q; scanf("%d", &q); while(q--) { int n, k; scanf("%d%d", &n, &k); int cnt = 0; while(n > 1 && n % 2 == 1) { ++cnt; n /= 2; } printf("%d\n", dp[cnt][k]); } return 0; }
相关文章推荐
- Codeforces 472G Design Tutorial: Increase the Constraints(分块+FFT)
- HDU.1023 Train Problem II【大数除法、卡特兰数】--用于求出栈的n种方式(3.15)
- 属性readwrite,readonly,assign,retain,copy,nonatomic 各是什么作用,在那种情况下用
- Error:Execution failed for task ':processDebugResources'.
- HDFS API文件上传报错 Exception in thread "main" .......: Wrong FS: file:///
- SGI STL (7) :: why stl containers have their own iterators?
- sakai作业系统
- HDU 2473 Junk-Mail Filter(并查集删点)
- http://blog.csdn.net/pizi0475/article/details/7768597
- 220. Contains Duplicate III
- PowerDesigner打开设计文件后提示failed to read the fileXXX的解决办法
- Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift
- 使用Genymotion调试出现错误INSTALL_FAILED_CPU_ABI_INCOMPATI
- B - Pairs Forming LCM——(LightOJ 1236)
- mybaits中的<trim>标签的作用
- sakai创建工具的过程,以roster2为例
- IBM openblockchain学习(一)--obc-peer环境搭建
- 219. Contains Duplicate II
- sakai和jcloud操作流程
- 20160315 Sail Studio 2244 剪格子,2324 N^3,2230 K好数