HDU 5976 Detachment

来源:互联网 发布:mysql设置primary key 编辑:程序博客网 时间:2024/05/21 18:35

Detachment

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 207    Accepted Submission(s): 74


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 ( aiaj when i≠j).
2.Make this multidimensional space size s as large as possible (s= a1a2*...).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
 

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
14
 

Sample Output
4
 

Source
2016ACM/ICPC亚洲区大连站-重现赛(感谢大连海事大学)
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:  5981 5979 5978 5977 5975 

 



考虑到最优解只能是2+3+4+....+n -y==x的情况下。

如果y为0 把1直接加到n上面

如果y为1.1扣掉就好了。。

如果y为2,扣掉2就行了。。然后1加到n上。。

如果y》3 ,从中间扣掉一个y-1 1扣掉就行了。。

因为有除法,,所以先预处理阶层,,,然后瞎几把二分找到   n和y的值。。

取个逆元就行了。

#include<bits/stdc++.h>#include <cstdio>#include <algorithm>using namespace std;typedef long long ll;typedef pair<int,int> pll;const ll mod=1e9+7;ll pow(ll a,ll b,ll c){    ll res=1;    while(b)    {        if(b&1)            res=res*a%c;        a=a*a%c;        b>>=1;    }    return res;}int main(){    int t;    ll fac[100005];    fac[0]=1;    for(int i=1; i<=100000; i++)        fac[i]=fac[i-1]*i%mod;    scanf("%d",&t);    while(t--)    {        ll n;        scanf("%lld",&n);        if(n==1)        {            cout<<n<<endl;            continue;        }        ll y;        ll m;        ll l=0,r=100000;        while(l<=r)        {            ll mid=(l+r)/2;            if((mid*(mid+1)/2)>=n)            {                m=mid;                y=m*(m+1)/2-n;                r=mid-1;            }            else                l=mid+1;        }        if(y==0)            printf("%lld\n",fac[m+1]*pow(m,mod-2,mod)%mod);        else if(y==1)            printf("%lld\n",fac[m]%mod);        else if(y==2)            printf("%lld\n",fac[m+1]*pow(2LL*m,mod-2,mod)%mod);        else            printf("%lld\n",fac[m]*pow(y-1,mod-2,mod)%mod);    }    return 0;}

0 0
原创粉丝点击