mint &operator+=(const mint &a) { x += a.x; if (x >= mod) x -= mod; return *this; } mint &operator-=(const mint &a) { x += mod - a.x; if (x >= mod) x -= mod; return *this; } mint &operator*=(const mint &a) { x = (ull)x * a.x % mod; return *this; } mint pow(ll pw)const{ mint res = 1; mint cur = *this; while (pw) { if (pw & 1) res *= cur; cur *= cur; pw >>= 1; } return res; } mint inv()const{ assert(x != 0); uint t = x; uint res = 1; while (t != 1) { uint z = mod / t; res = (ull)res * (mod - z) % mod; t = mod - t * z; } return res; } mint &operator/=(const mint &a) { return *this *= a.inv(); } mint operator+(const mint &a) const { returnmint(*this) += a; } mint operator-(const mint &a) const { returnmint(*this) -= a; } mint operator*(const mint &a) const { returnmint(*this) *= a; } mint operator/(const mint &a) const { returnmint(*this) /= a; }
boolsqrt(mint &res)const{ if (mod == 2 || x == 0) { res = *this; returntrue; } if (pow((mod - 1) / 2) != 1) returnfalse; if (mod % 4 == 3) { res = pow((mod + 1) / 4); returntrue; } int pw = (mod - 1) / 2; int K = 30; while ((1 << K) > pw) K--; while (true) { mint t = myRand(mod); mint a = 0, b = 0, c = 1; for (int k = K; k >= 0; k--) { a = b * b; b = b * c * 2; c = c * c + a * *this; if (((pw >> k) & 1) == 0) continue; a = b; b = b * t + c; c = c * t + a * *this; } if (b == 0) continue; c -= 1; c *= mint() - b.inv(); if (c * c == *this) { res = c; returntrue; } } assert(false); }
booloperator==(const mint &a) const { return x == a.x; } booloperator!=(const mint &a) const { return x != a.x; } booloperator<(const mint &a) const { return x < a.x; } }; template <uint mod = MOD> struct Factorials { using Mint = mint<mod>; vector<Mint> f, fi;
Factorials() : f(), fi() {} Factorials(int n) { n += 10; f = vector<Mint>(n); fi = vector<Mint>(n); f[0] = 1; for (int i = 1; i < n; i++) f[i] = f[i - 1] * i; fi[n - 1] = f[n - 1].inv(); for (int i = n - 1; i > 0; i--) fi[i - 1] = fi[i] * i; }
Mint C(int n, int k){ if (k < 0 || k > n) return0; return f[n] * fi[k] * fi[n - k]; } }; template <uint mod = MOD> struct Powers { using Mint = mint<mod>; vector<Mint> p, pi;
Powers() : p(), pi() {} Powers(int n, Mint x) { n += 10; if (x == 0) { p = vector<Mint>(n); p[0] = 1; } else { p = vector<Mint>(n); pi = vector<Mint>(n); p[0] = pi[0] = 1; Mint xi = x.inv(); for (int i = 1; i < n; i++) { p[i] = p[i - 1] * x; pi[i] = pi[i - 1] * xi; } } }
Mint pow(int n){ if (n >= 0) return p[n]; else return pi[-n]; } }; template <uint mod = MOD> struct Inverses { using Mint = mint<mod>; vector<Mint> ii;
Inverses() : ii() {} Inverses(int n) { n += 10; ii = vector<Mint>(n); ii[1] = 1; for (int x = 2; x < n; x++) ii[x] = Mint() - ii[mod % x] * (mod / x); }
Mint inv(Mint x){ assert(x != 0); uint t = x.x; uint res = 1; while (t >= (int)ii.size()) { uint z = mod / t; res = (ull)res * (mod - z) % mod; t = mod - t * z; } return ii[t] * res; } }; using Mint = mint<>; //-----------------------variable----------------------- ll n, l, r, z; Mint C[MAXN][MAXN]; Mint dp[62][MAXN]; // 第i位剩余j个1可以填到当前位 //-----------------------function----------------------- Mint solver(ll n, ll r, ll z){ mem(dp, 0); dp[61][0] = 1; for (int k = 60; k >= 0; k--) { // 从低位开始枚举 int c = (z >> k) & 1; // 当前位的01情况 for (int x = 0; x <= n; x++) { if (dp[k + 1][x] == 0) continue; int y = 2 * x + ((r >> k) & 1); for (int t = c; t <= y && t <= n; t += 2) { // 枚举当前为1的个数 dp[k][min(n, y - t)] += dp[k + 1][x] * C[n][t]; } } } Mint res = 0; for (int i = 0; i <= n; i++) { res += dp[0][i]; } return res; } intmain(){ #ifdef LOCAL clock_t TIME = clock(); freopen("G:\\Cworkspace\\data\\in.txt", "r", stdin); freopen("G:\\Cworkspace\\data\\out.txt", "w", stdout); #endif
//*********************************YounGCY*******************************// //预处理组合数 for (int i = 0; i < MAXN; i++) C[i][i] = C[i][0] = 1; for (int i = 0; i < MAXN; i++) for (int j = 0; j < i; j++) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];