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

     
  • 相关阅读:
    PreparedStatement/Statement处理insert update等操作时乱码,以及URL
    MySQL unique 注意
    web乱码解决了
    实用工具及Chrome插件及实用网站(持续更新中...)
    前端常用算法集合,持续更新...
    各种问题汇总解决方法,持续更新中...
    node实现自动化图片切割压缩, 部署页面
    移动端图片缩放插件Pinchzoom.js
    提示框简单封装
    模拟滚动条
  • 原文地址:https://www.cnblogs.com/mfys/p/7544767.html
Copyright © 2011-2022 走看看