给出a,求递归式g(k)的初始条件g(0);
可以看出来g(a) = 1,从后往前推。写个模拟程序可以看出来其实g(0) = 2^a,那么就是一个简单地快速幂取模问题了。
#include <cstdio> #include <iostream> #include <sstream> #include <cmath> #include <cstring> #include <cstdlib> #include <string> #include <vector> #include <map> #include <set> #include <queue> #include <stack> #include <algorithm> using namespace std; #define ll unsigned long long #define _cle(m, a) memset(m, a, sizeof(m)) #define repu(i, a, b) for(int i = a; i < b; i++) #define repd(i, a, b) for(int i = b; i >= a; i--) #define sfi(n) scanf("%d", &n) #define pfi(n) printf("%d ", n) #define MAXN 4010 const int N = 20005; #define mod 1000000007 ll modexp(ll a, ll b) //(a^b)%mod; { ll ret = 1; ll tmp = a; while(b) { if(b&0x1) ret = ret*tmp%mod; tmp = tmp*tmp%mod; b >>= 1; } return ret; } int main() { ll a; while(~scanf("%I64d", &a)) { ll ans = modexp((ll)2, a); printf("%I64d ", ans); } return 0; }