HDU 5976 Detachment - dblank

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)

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

Maximum s you can get modulo 10^9+7. Note that we wants to be greatest product before modulo 10^9+7.

Sample Input

Sample Output


#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)
    ll res = 1;
            res = res * x % Mod;
        x = x*x%Mod;
    return res;
int b_s(int x)
    int l = 1, r = cnt, mid;
        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;
    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;
        int n;
        ll ans =0;
        scanf("%d", &n);
            printf("%d\n", n);
        int id = b_s(n);
        int res = 0;
        res = n - a[id-1];
        int l = res / id;
            ans = fact[id+1-res] * (fact[id+2]*inv[id+2-res]%Mod)%Mod;
            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;


已有 3 条评论
  1. CharlesUrisk

    More info!..

    CharlesUrisk 回复
  2. JefferyTiend

    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

    JefferyTiend 回复
  3. PhilipPsype

    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.


    PhilipPsype 回复