Detachment
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 437 Accepted Submission(s): 144
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
思路:从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);
}
}
374



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



