zoukankan      html  css  js  c++  java
  • hdu 5793 A Boring Question (快速幂+逆元)(规律题)

    官方推导公式:

    0k1,k2,kmn1j<m(kjkj+1) =sum_{0leq k_{1}leq k_{2}leqcdots leq k_{m}leq n}prod_{1leq j< m}inom{k_{j+1}}{k_{j}}

    =0k1k2kmn1j<m(kjkj+1) =sum_{k_{m}=0}^{n}sum_{k_{m-1}=0}^{k_{m}}cdots sum_{k_{1}=0}^{k_{2}}prod_{1leq j< m}inom{k_{j+1}}{k_{j}}

    =km=0nkm1=0kmk1=0k21j<m(kjkj+1) =sum_{k_{m}=0}^{n}left { inom{k_{m}}{k_{m-1}} sum_{k_{m-1}=0}^{k_{m}} left { inom{k_{m-1}}{k_{m-2}} cdots sum_{k_{1}=0}^{k_{2}}inom{k_{2}}{k_{1}} ight } ight }

    =km=0n{(km1km)km1=0km{(km2km1)k1=0k2(k1k2)}}

     =sum_{k_{m}=0}^{n}left { inom{k_{m}}{k_{m-1}} sum_{k_{m-1}=0}^{k_{m}} left { inom{k_{m-1}}{k_{m-2}} cdots sum_{k_{1}=0}^{k_{2}}inom{k_{2}}{k_{1}} ight } ight }=km=0n{(km1km)km1=0km{(km2km1)k1=0k2(k1k2)}} =sum_{k_{m}=0}^{n}left { inom{k_{m}}{k_{m-1}} sum_{k_{m-1}=0}^{k_{m}} left { inom{k_{m-1}}{k_{m-2}} cdots sum_{k_{2}=0}^{k_{3}}inom{k_{3}}{k_{2}}2^{k_{2}} ight } ight }

    =km=0n{(km1km)km1=0km{(km2km1)k2=0k3(k2k3)2k2}} =sum_{k_{m}=0}^{n}m^{k_{m}}

    =km=0nmkm =frac{m^{n+1} - 1}{m - 1}

    =m1mn+11

    自己找的规律是求:ans=m^0+m^1+m^2+...+m^n,也就是等比数列的前n+1项和

    /*by*/
    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <cstring>
    using namespace std;
    typedef long long LL;
    const LL N=2010;
    const LL mod=1000000007;
    const LL INF=0x3f3f3f;
    LL quickpow(LL m, LL n)
    {
        LL b = 1;
        while(n > 0) {
            if(n & 1)
                b = (b * m) % mod;
            n = n >> 1 ;
            m = (m * m) % mod;
        }
        return b;
    }
    int main()
    {
        int T;
        cin>>T;
        while(T--) {
            LL n,m;
            scanf("%lld%lld",&n,&m);
            LL ans=0;
            ans=quickpow(m,n+1)-1;
            ans=ans*quickpow(m-1,mod-2)%mod;/*求逆元*/
            printf("%lld
    ",ans%mod);
        }
        return 0;
    }
  • 相关阅读:
    Oracle和SQLServer中实现跨库查询
    sqlserver中创建链接服务器
    无法从命令行或调试器启动服务,必须首先安装Windows服务(使用installutil.exe),然后用ServerExplorer、Windows服务器管理工具或NET START命令启动它
    Win8系统运行程序提示“占位程序接收到错误数据”的解决方法
    设计模式——简单工厂模式
    设计模式——单例模式
    设计模式——观察者模式
    三一集团提前批java面经
    form表单传到后端的数据乱码
    Failed to obtain the JDBC Connection + Access denied for user 'XXX'@'localhost' (using password: YES)
  • 原文地址:https://www.cnblogs.com/yu0111/p/5740013.html
Copyright © 2011-2022 走看看