Detachment
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 895 Accepted Submission(s): 258
Problem Description
In a highly developed alien society, the habitats are almost infinite dimensional space.
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)
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)
Input
The first line is an integer T,meaning the number of test cases.
Then T lines follow. Each line contains one integer x.
1≤T≤10^6, 1≤x≤10^9
Then T lines follow. Each line contains one integer x.
1≤T≤10^6, 1≤x≤10^9
Output
Maximum s you can get modulo 10^9+7. Note that we wants to be greatest product before modulo 10^9+7.
Sample Input
1 4
Sample Output
4
Source
刚开始读错题意了。。。。
好吧,读对也过不了=.=
贪心
构造2,3,4,5,6一直到总和不超过x
举个例更好说
x=30
那么就是2,3,4,5,6,5
最后一个5重复了,是用前面的数去补他还是,用他去补前面的数,举了几个例子是往前补更优,证明不详。。。。。。
所以就这样贪心的构造,
求乘积时可以先处理出来阶乘,然后取模除一除
#include<bits/stdc++.h>
using namespace std;
long long mo=1e9+7;
long long f[1000005];
long long poww(long long a,long long x)
{
long long ans=1,t=a;
while(x)
{
if(x&1)
ans*=t;
t*=t;
ans%=mo;
t%=mo;
x>>=1;
}
return ans;
}
void init()
{
f[0]=1;
for(int i=1;i<=1000000;i++)
{
f[i]=(f[i-1]*i)%mo;
}
return ;
}
long long solve(long long x,long long y)
{
return (x*poww(y,mo-2))%mo;
}
int main()
{
init();
int T;
long long x;
scanf("%d",&T);
while(T--)
{
scanf("%lld",&x);
if(x==1)
{
printf("1\n");
continue;
}
long long le=0,ri=x,mid,res,sum,tt;
while(le<=ri)
{
mid=(le+ri)>>1;
if((mid+2)*(mid-1)/2<=x)
{
res=mid;
le=mid+1;
}
else
ri=mid-1;
}
// cout<<res<<endl;
sum=(res+2)*(res-1)/2;
tt=x-sum;
if(tt==res)
{
printf("%lld\n",(solve(f[res],2)*(res+2))%mo);
}
else
{
// cout<<res<<" "<<tt<<endl;
printf("%lld\n",(solve(f[res+1],res-tt+1)%mo));
}
}
return 0;
}