# HDU 5976 Detachment

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

思路:可以打表得到规律，一定是越连续越大，首先肯定是不会分出1的，因为乘积里面1是没有贡献的。所以从2开始，但是最后会有多余，我们就从后往前分配到这些连续的数上面。因为n很大，最多可能会分配出4w多个数字，所以还要阶乘打表，还有阶乘的逆元。

```
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
#pragma comment(linker, "/STACK:102400000,102400000")
#define endl '\n'
using namespace std;
const double eps = 1e-10, pi = acos(-1.0);
const int inf = 0x3f3f3f3f, N = 100000 + 200, Mod = 1000000007;
typedef long long ll;
ll a[N], fact[N], inv[N], cnt;
ll q_pow(ll x, ll y)
{
x%=Mod;
ll res = 1;
while(y)
{
if(y&1)
res = res * x % Mod;
x = x*x%Mod;
y>>=1;
}
return res;
}
int b_s(int x)
{
int l = 1, r = cnt, mid;
while(l<=r)
{
mid = (l+r)>>1;
if(a[mid] >= x)
r = mid - 1;
else l = mid + 1;
}
return l;
}
int main()
{
a[1] = 4;
int num = 4;
cnt = 1;
for(int i = 2;a[i-1]+num<=2000000000; i++)
{
a[i] = a[i-1] + num;
num++;
cnt++;
}
fact[1] = 1;
for(int i = 2; i<=cnt; i++)
{
fact[i] = fact[i-1]*i % Mod;
inv[i] = q_pow(fact[i], Mod-2);
}
inv[0] = q_pow(2, Mod-2);
int t;
cin>>t;
while(t--)
{
int n;
ll ans =0;
scanf("%d", &n);
if(n<=4)
{
printf("%d\n", n);
continue;
}
int id = b_s(n);
int res = 0;
res = n - a[id-1];
int l = res / id;
res--;
if(res+1<=id)
{
ans = fact[id+1-res] * (fact[id+2]*inv[id+2-res]%Mod)%Mod;
}
else
{
res-=id;
ans = fact[id+2-res%id]*inv[0]%Mod * (fact[id+3]*inv[id+3-res%id]%Mod)%Mod;
}
printf("%I64d\n", ans);
}
return 0;
}
```

最后更新于 2016-11-07 16:33:51 并被添加「HDU」标签，已有 485 位童鞋阅读过。

本站使用「署名 4.0 国际」创作共享协议，可自由转载、引用，但需署名作者且注明文章出处

More info!..

If you have been feeling stressed lately, but you are not sure how to deal with it, the advice in this article can help. Feelings of stress are increasingly common in today's world, but there are ways to help. This article will teach you some easy ways to overcome your stress.

vente viagra espagne vrai

ome people, especially those running on busy daily schedules tend to use the pills to help maintain weight since they can not afford to follow all the diet programs. This is not advised. It is recommended that one seek advice from a professional in this field before using the pills. This can save one from many dangers associated with the misuse.

The diet pills should always be taken whole. Some people tend to divide the pills to serve a longer period of time. This is not advised and can lead to ineffectiveness. If it is required that one takes a complete tablet, it means that a certain amount of the ingredients are required to achieve the desired goal. It is also recommended that one does not crush the pill and dissolve it in beverages. Chemicals found in beverages have the potential of neutralizing the desired nutrients in the pill thereby leading to ineffectiveness. The best way to take the tablets is swallowing them whole with a glass of water.

https://www.cialissansordonnancefr24.com/acheter-cialis-suisse/