Problem Description
已知 求
Input
多组输入,每组输入占一行,包含一个整数n(1 <= n <= )。
数据不超过300000组。
Output
对于每组输入,输出一行,包括一个数代表答案。
这个题我都不知道怎么给我乱搞出递推式的...
我们发现那我们设,然后我就通过观察法(真的是观察法!)发现其中, 。我们就猜出了递推式。然后,为什么我就会莫名其妙想到了矩阵快速幂呢???,然后我就tle了12发。这里我们是可以推出通项公式的。那么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;
}