#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<cmath>
#include<iostream>
using namespace std;
#define maxn 50000
const int mod = 1e9+7;
typedef __int64 LL;
LL sum[maxn];
LL mu[maxn];
void init()
{
mu[1]=1;
for(int i=2; i<maxn; i++)
{
sum[i]=sum[i-1]+i;
mu[i]=(mu[i-1]*i)%mod;
}
sum[1]=1;
}
LL mult(LL a,int n) // 快速幂
{
LL ans=1;
while(n)
{
if(n&1)ans=(ans*a)%mod;
a=(a*a)%mod;
n>>=1;
}
return ans;
}
int main()
{
init();
int T;
scanf("%d",&T);
while(T--)
{
LL x;
scanf("%I64d",&x);
int index=lower_bound(sum,sum+maxn,x)-sum;
LL ans;
if(sum[index]==x)
ans=mu[index];
else
{
if(sum[index]==x+1)
ans=((mu[index+1]*mult(index,mod-2))%mod*mult(2,mod-2))%mod;
else
ans=(mu[index]*mult(sum[index]-x,mod-2))%mod;
}
printf("%I64d\n",ans);
}
return 0;
}
Detachment - HDU 5976
最新推荐文章于 2020-07-07 23:48:24 发布