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
| #include<bits/stdc++.h> #define RG register #define file(x) freopen(#x".in", "r", stdin);freopen(#x".out", "w", stdout); #define clear(x, y) memset(x, y, sizeof(x)); using namespace std;
inline int read() { int data=0, w=1; char ch=getchar(); while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar(); if(ch=='-') w=-1, ch=getchar(); while(ch>='0'&&ch<='9') data=(data<<3)+(data<<1)+(ch^48), ch=getchar(); return data*w; }
const int maxn(510), yl(1e9+7); int f[maxn][maxn * maxn], frac[maxn], inv[maxn], n, e, T, c[maxn][maxn]; inline int fastpow(int x, int y) { int base=x%yl, ans=1; while(y) { if(y&1) ans=(1ll*ans*base)%yl; base=(1ll*base*base)%yl; y>>=1; } return ans%yl; } int main() { frac[0]=1; for(RG int i=1;i<=maxn-5;i++) frac[i]=1ll*frac[i-1]*i%yl, inv[i]=fastpow(frac[i], yl-2); f[1][0]=f[1][1]=1; for(n=2;n<=maxn-5;n++) { for(e=0;e<=(n-1)*n>>1;e++) { f[n][e]=f[n-1][e]; if(e-n>=0) f[n][e]=(1ll*f[n][e]-1ll*f[n-1][e-n]+yl)%yl; if(e>0) f[n][e]=(1ll*f[n][e]+1ll*f[n][e-1])%yl; } for(e=((n-1)*n>>1)+1;e<=(n+1)*n>>1;e++) f[n][e]=f[n][e-1]; } T=read(); #define sqr(a) ((1ll*(a))*(1ll*(a))%yl) while(T--) { n=read(); e=read(); long long ans=0; for(RG int i=1;i<=n;i++) ans=(1ll*ans+1ll*f[i][min(e, (i-1)*i>>1)]*(n-i+1)%yl*sqr(1ll*frac[n]*inv[i]%yl)%yl)%yl; printf("%lld\n", ans); } return 0; }
|