按位推下式子就行了。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 2505 #define mod 2333 using namespace std; long long t,n,k,c[maxn][maxn],s[maxn][maxn],to[maxn],ret=0,bitn[maxn],bitk[maxn]; void get_table() { c[0][0]=1;for (long long i=0;i<mod;i++) s[0][i]=1; for (long long i=1;i<mod;i++) { c[i][0]=s[i][0]=1; for (long long j=1;j<mod;j++) { c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod; s[i][j]=(s[i][j-1]+c[i][j])%mod; } } to[0]=1; for (long long i=1;i<mod;i++) to[i]=to[i-1]*2%mod; } void get_bit(long long n,long long k) { ret=0; while (n) {bitn[++ret]=n%mod;n/=mod;} for (long long i=1;i<=ret;i++) {bitk[i]=k%mod;k/=mod;} } long long f_pow(long long x,long long y) { long long base=x,ans=1; while (y) { if (y&1) ans=(ans*base)%mod; base=(base*base)%mod; y>>=1; } return ans; } long long inv(long long x) {return f_pow(x,2331);} long long lucas_s(long long pos,long long r) { if (!pos) return 1; long long ans1=s[bitn[pos]][bitk[pos]-1]*r%mod,ans2=c[bitn[pos]][bitk[pos]]*lucas_s(pos-1,r*inv(to[bitn[pos-1]])%mod)%mod; return (ans1+ans2)%mod; } int main() { scanf("%lld",&t);get_table(); for (long long i=1;i<=t;i++) { scanf("%lld%lld",&n,&k); get_bit(n,k); long long base=1; for (long long i=ret-1;i>=1;i--) base=(base*to[bitn[i]])%mod; printf("%lld\n",lucas_s(ret,base)%mod); } return 0; }