Detachment
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1723 Accepted Submission(s): 481
In the history of this planet,there is an old puzzle.
You have a line segment with x units’ length representing one dimension.The line segment can be split into a number of small line segments: a1,a2 , … (x= a1+a2 +…) assigned to different dimensions. And then, the multidimensional space has been established. Now there are two requirements for this space:
1.Two different small line segments cannot be equal ( ai≠aj when i≠j).
2.Make this multidimensional space size s as large as possible (s= a1∗a2 *...).Note that it allows to keep one dimension.That's to say, the number of ai can be only one.
Now can you solve this question and find the maximum size of the space?(For the final number is too large,your answer will be modulo 10^9+7)
Then T lines follow. Each line contains one integer x.
1≤T≤10^6, 1≤x≤10^9
1 4
4
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;
#define LL long long
const LL maxn = 45000+44;
const LL mod = 1e9+7;
LL x[maxn];
LL j[maxn];
LL qkm(LL base,LL mi){
LL ans=1;
base%=mod;
while(mi){
if(mi&1) ans=ans*base;
base=base*base;
mi>>=1;
base%=mod;
ans%=mod;
}
return ans;
}
int main()
{
x[1]=0;
LL cnt;
for(cnt=2;;cnt++){
x[cnt]=x[cnt-1]+cnt;
if(x[cnt]>=1e9) break;
}
j[1]=1;
for(LL i=2;i<=cnt;i++){
j[i]=j[i-1]*i%mod;
}
LL T;scanf("%lld",&T);
while(T--){
LL n;scanf("%lld",&n);
LL now=0;
LL k=0;
k=upper_bound(x+1,x+1+cnt,n)-x;
if(x[k]>n) k--;
now=x[k];
// printf("%lld %lld\n",now,k);
LL shen=n-now;
LL ans;
if(n<=4) {
printf("%lld\n",n);
continue;
}
if(shen==k){
ans=j[k+2]*qkm(2,mod-2)%mod*qkm(k+1,mod-2)%mod;//!!!!NIYUAN;
}
else
{
ans=j[k+1]*qkm(k+1-shen,mod-2)%mod;
}
printf("%lld\n",ans);
}
return 0;
}
349


&spm=1001.2101.3001.11974&articleId=78127193&d=1&t=3&u=32298b63ffc04bdfb0c0de1f4dab8a60)

被折叠的 条评论
为什么被折叠?



