HDU 5976

来源:互联网 发布:三唑仑淘宝上输什么 编辑:程序博客网 时间:2024/06/05 09:51

Detachment

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


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亚洲区大连站-重现赛(感谢大连海事大学) 
 

题意:
给你一个数,让你拆成任意个不同的数,让他们相乘最大,输出结果。

POINT:
可知n<=4时,不用拆直接输出。
n>4:先尝试拆成2 3 4 5 6 ^n,最后剩一个数是[0,n]。当等于n时,变成3,4,5,6,7,n+2 没有n-1.别的情况就是从后往前依次加一个1.
打表用阶乘o(1)的效率算。
查找用二分,才不会tle。


#include <iostream>#include <stdio.h>#include <math.h>#include <string.h>#include <vector>#include <algorithm>using namespace std;#define LL long longconst 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;}


原创粉丝点击