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  逆元模板

     
  • 相关阅读:
    Python之并发编程(三)生产者与消费者模型
    Python之并发编程(四)多线程(相关理论)
    cookiesession okenkey四大参数解析
    常见http返回的状态码
    for遍历用例数据时,报错:TypeError: list indices must be integers, not dict,'int' object is not iterable解决方法
    python中调用函数时,参数顺序与参数赋值问题
    自动化测试用例中的raise
    python --------简单的socket通话实现例子
    python---------------logging
    Monkey
  • 原文地址:https://www.cnblogs.com/mfys/p/7544767.html
Copyright © 2011-2022 走看看