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

     
  • 相关阅读:
    Scons 三
    Scons 二
    vs code插件
    Scons一
    实例演示 C# 中 Dictionary<Key, Value> 的检索速度远远大于 hobbyList.Where(c => c.UserId == user.Id)
    ASP.NET Core 如何用 Cookie 来做身份验证
    如何设计出和 ASP.NET Core 中 Middleware 一样的 API 方法?
    小记编程语言的设计
    解决 VS2019 打开 edmx 文件时没有 Diagram 视图的 Bug
    一款回到顶部的 jQuery 插件,支持 Div 中的滚动条回到顶部
  • 原文地址:https://www.cnblogs.com/mfys/p/7544767.html
Copyright © 2011-2022 走看看