HDU 6467 简单数学题

Problem Description

已知 F(n)=\sum_{i=1}^{n}(i\times\sum_{j=i}^{n}\mathrm{C}_j^i)F(n)\mod\1000000007

Input

多组输入,每组输入占一行,包含一个整数n(1 <= n <= 10^{18})。
数据不超过300000组。

Output

对于每组输入,输出一行,包括一个数代表答案。

这个题我都不知道怎么给我乱搞出递推式的...

我们发现F(n)-F(n-1)=\sum_{i=1}^{n}n\mathrm{C}_n^i那我们设\sum_{i=1}^{n}n\mathrm{C}_n^i=T(n),然后我就通过观察法(真的是观察法!)发现T(n)=2\times T(n-1)+2^{n-1}其中T(1)=1,F(0)=0    。我们就猜出了递推式F(n)=\sum _{i=1}^nT(n)。然后,为什么我就会莫名其妙想到了矩阵快速幂呢???,然后我就tle了12发。这里我们是可以推出通项公式F(n)=(n-1)*2^{n}+1的。那么log变o(1),完美解决!

Problem : 1007 ( 简单数学题 )     Judge Status : 
RunId : 19433    Language : G++    Author : 
Code Render Status : Rendered By HDOJ G++ Code Render Version 0.01 Beta
#include <iostream>
#include<cstdio>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#define rg register
typedef long long ll;
using namespace std;
ll read(){
    ll ans=0,flag=1;char ch;
    while((ch=getchar())<'0'||ch>'9') if(ch=='-') flag=-1; else if(ch==EOF) exit(0);
    while(ch>='0'&&ch<='9'){ans=ans*10+ch-'0';ch=getchar();}
    return ans*flag;
}
const ll mod=1000000007;
ll fastpow(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1) ans=(ans*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return ans;
}
int main(){
    ll n;
    while(cin>>n){

    printf("%lld\n",(((n-1)%mod*fastpow(2,n))%mod+1)%mod );


    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/ffscas/article/details/88604089