您的位置:首页 > 其它

2016 ICPC大连赛区 hdu5976 Detachment

2016-11-18 21:53 344 查看


Detachment

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 437    Accepted Submission(s): 144


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)

 

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

1
4

 

Sample Output

4

 

Source

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

 

Recommend

wange2014   |   We have carefully selected several similar problems for you:  5981 5977 5975 5973 5972 
题意:给你一个x,你可以任意分成n段,但每一段的长度不一样,求a1*a2...*an的最大值。

思路:从1开始枚举你会发现,拆得越小是越划算的(1除外,1*任何数为1),所以把x尽可能拆小就能得到最大值,因此我们维护前缀和和前缀积,二分找到前缀和大于等于x的位置,那么该前缀和只要去掉其中某个值就能得到x,套个逆元就可以了,但如果去掉的值刚好是1的话,那么我们选择去掉头和尾再加上pos+1就能得到x,一样用逆元就可以了。下面给代码:

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<queue>
#include<functional>
typedef long long LL;
using namespace std;
#define maxn 45000
#define ll l,mid,now<<1
#define rr mid+1,r,now<<1|1
#define lson l1,mid,l2,r2,now<<1
#define rson mid+1,r1,l2,r2,now<<1|1
#define pi 3.14159
const int mod = 1e9 + 7;
int sum[maxn];
LL mul[maxn];
LL quitemod(LL a, LL b){
LL ans = 1;
a = a%mod;
while (b){
if (b & 1)
ans = (ans*a) % mod;
b >>= 1;
a = (a*a) % mod;
}
return ans;
}
int main(){
sum[1] = 0;
mul[1] = 1;
for (int i = 2; i<45000; i++){
sum[i] = sum[i - 1] + i;
mul[i] = mul[i - 1]*i;
mul[i] %= mod;
}
int t;
scanf("%d", &t);
while (t--){
int x;
scanf("%d", &x);
if (x == 1){
printf("1\n");
continue;
}
int pos = lower_bound(sum, sum + 45000, x) - sum;
LL now = sum[pos] - x;
LL ans;
if (now){
if (now == 1){
ans = mul[pos] * quitemod(pos, mod - 2) % mod*quitemod(2, mod - 2) % mod*(pos + 1) % mod;
}
else
ans = mul[pos] * quitemod(now, mod - 2) % mod;
}
else
ans = mul[pos];
printf("%lld\n", ans);

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: