zoukankan      html  css  js  c++  java
  • hdu5967数学找规律+逆元

    Detachment

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 1686    Accepted Submission(s): 467


    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;
    const int N=1e5+88;
    const int mod=1e9+7;
    long long add[N],mul[N];
    void init(){
       add[0]=add[1]=0;
       mul[1]=mul[0]=1;
       for(int i=2;i<N;++i) {
        add[i]=i+add[i-1];
        mul[i]=(mul[i-1]*i)%mod;
       }
    }
    long long kuai(long long base,long long k){
       long long ans=1;
       while(k){
        if(k&1) ans=(ans*base)%mod;
        k>>=1;
        base=(base*base)%mod;
       }
       return ans;
    }
    int main(){
       init();
       int T;
       for(scanf("%d",&T);T--;){
        int x;
        scanf("%d",&x);
        if(x<=4) {printf("%d
    ",x);continue;}
        int l=2,r=N-1,ans;
        while(l<=r){
            int mid=(l+r)>>1;
            if(add[mid]<=x) {ans=mid,l=mid+1;}
            else r=mid-1;
        }
        int temp=x-add[ans];
        if(temp==0) printf("%I64d
    ",mul[ans]);
        else if(temp == ans) printf("%I64d
    ", mul[ans]*kuai(2, mod-2)%mod*(ans+2)%mod);
        else printf("%I64d
    ",((mul[ans+1]*mul[ans-temp])%mod*kuai(mul[ans-temp+1],mod-2))%mod);
       }
    }

    http://blog.csdn.net/chen_ze_hua/article/details/53081001  逆元模板

     
  • 相关阅读:
    L1-050 倒数第N个字符串 (15分)
    Oracle存储过程的疑难问题
    Linux的细节
    Linux字符设备和块设备的区别
    Shell变量
    游标的常用属性
    Oracle中Execute Immediate用法
    Oracle中的sqlerrm和sqlcode
    Oracle把一个表的数据复制到另一个表中
    Oracle的差异增量和累积增量
  • 原文地址:https://www.cnblogs.com/mfys/p/7544767.html
Copyright © 2011-2022 走看看