使用Angular下拉自動載入
阿新 • • 發佈:2020-11-03
題意
- 求\(\displaystyle \sum_{i=0}^k {n \choose i} \mod 2333\)
直接推式子:
令\(p=2333,k=tp+r\)
\[\displaystyle \sum_{i=0}^k {n \choose i} \\ = \sum_{i=0}^{tp+r} {n \choose i} \\ =\sum_{i=0}^{tp-1} {n \choose i} + \sum_{i=0}^{r} {n \choose {tp+i}} \\ =\sum_{i=0}^{tp-1} {\frac n p \choose \frac i p} {n \% p \choose i \% p} + \sum_{i=0}^{r} {\frac n p \choose t} {n \% p \choose i} \\ \]那麼令\(\displaystyle S(n,k) = \sum_{i=0}^k {n \choose i}\),就可以得到:
\[S(n,k)=2^{n \% p} \cdot S(\frac n p, \frac k p -1) + {\frac n p \choose i} \cdot S(n \% p,k \% r) \]遞迴求解即可
#include<bits/stdc++.h> #define For(i, a, b) for(int i = (a), en = (b); i <= en; ++i) #define Rof(i, a, b) for(int i = (a), en = (b); i >= en; --i) #define Tra(u, i) for(int i = hd[u]; ~i; i = e[i].net) #define cst const #define LL long long #define DD double #define LD long double #define pb push_back #define mp make_pair #define fir first #define sec second #define inf 0x3f3f3f3f #define Inf 0x3f3f3f3f3f3f3f3f #define eps 1e-12 #define mod 2333 using namespace std; int t, fac[mod + 5], ifac[mod + 5]; LL n, k; template <class T> void read(T &x){ char ch; bool ok; for(ok = 0, ch = getchar(); !isdigit(ch); ch = getchar()) if(ch == '-') ok = 1; for(x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar()); if(ok) x = -x; } int fp(int x, int y){ int asi = 1; while(y){ if(y & 1) asi = 1ll * asi * x % mod; x = 1ll * x * x % mod; y >>= 1; } return asi; } int c(int x, int y){return x < y ? 0 : 1ll * fac[x] * ifac[y] % mod * ifac[x - y] % mod;} int luc(LL x, LL y){ if(!y) return 1; if(!x) return 0; return 1ll * c(x % mod, y % mod) * luc(x / mod, y / mod) % mod; } int f[mod + 5][mod + 5]; map<LL, map<LL, int> > ma; int get_s(LL x, LL y){ if(y < 0) return 0; if(x < mod && y < mod) return f[x][y]; if(ma[x][y]) return ma[x][y] - 1; int asi = 1ll * luc(x / mod, y / mod) * get_s(x % mod, y % mod) % mod; asi = (asi + 1ll * fp(2, x % mod) * get_s(x / mod, y / mod - 1) % mod) % mod; ma[x][y] = asi + 1; return asi; } int main(){ //freopen("in", "r", stdin); //freopen("c.out", "w", stdout); fac[0] = fac[1] = ifac[0] = ifac[1] = 1; For(i, 2, mod - 1) fac[i] = 1ll * fac[i - 1] * i % mod; ifac[mod - 1] = fp(fac[mod - 1], mod - 2); Rof(i, mod - 2, 2) ifac[i] = 1ll * ifac[i + 1] * (i + 1) % mod; For(i, 0, mod) For(j, 0, mod) f[i][j] = (1ll * f[i][j] + (j ? f[i][j - 1] : 0) + c(i, j)) % mod; read(t); while(t--){ read(n); read(k); printf("%d\n", get_s(n, k)); } return 0; }