zoukankan      html  css  js  c++  java
  • HDU 5976 Detachment

    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 ( 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
    1
    4
     
    Sample Output
    4
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    typedef long long LL;
    const int MAXN=1e5+5;
    const LL MOD=1e9+7;
    int has[MAXN],sum[MAXN],inv[MAXN],tot;
    LL pro[MAXN];
    void table() { has[2]=5; tot=2; while(has[tot]<=1e9) { tot++; has[tot]=has[tot-1]+tot+1; } sum[1]=2; for(int i=2;sum[i-1]<=1e9;i++) sum[i]=sum[i-1]+i+1; inv[1]=pro[1]=1; for(int i=2;i<MAXN;i++) (pro[i]=pro[i-1]*i)%=MOD; for(int i=2;i<MAXN;i++) inv[i]=(MOD-MOD/i)*inv[MOD%i]%MOD; } void solve(int x) { int num=upper_bound(has+2,has+tot,x)-has-1; int more=x-sum[num]; int l,r; l=2+more/num; r=l+num-1; LL res; if(more%num) res=pro[r+1]*inv[l-1]%MOD*inv[r+1-more%num]%MOD; else res=pro[r]*inv[l-1]%MOD; printf("%lld ",res); } int main() { table(); int T; scanf("%d",&T); while(T--) { int x; scanf("%d",&x); if(x==1||x==2||x==3||x==4) { printf("%d ",x); continue; } solve(x); } return 0; }
  • 相关阅读:
    软件工程第六次作业
    软件工程第五次作业
    软件工程第四次作业
    软件工程第三次作业
    软件工程第二次作业
    软件工程第一次作业
    《CLSZS团队》:团队项目选题报告
    计算机软件工程 作业五
    计算机软件工程 作业四
    计算机软件工程 作业三
  • 原文地址:https://www.cnblogs.com/homura/p/6040850.html
Copyright © 2011-2022 走看看