数学题。f(n) = 2^(n-1) mod (1e9+7)。
1 #include <cstdio> 2 3 #define MAXN 100005 4 5 char buf[MAXN]; 6 __int64 phi = 1e9+6; 7 __int64 mod = 1e9+7; 8 9 __int64 power2(__int64 n) { 10 __int64 ret = 1, base = 2; 11 12 --n; 13 while (n) { 14 if (n & 1) 15 ret = ret * base % mod; 16 base = base*base%mod; 17 n >>= 1; 18 } 19 return ret; 20 } 21 22 int main() { 23 __int64 tmp; 24 __int64 i, j; 25 26 while (scanf("%s", buf) != EOF) { 27 tmp = 0; 28 for (i=0; buf[i]; ++i) { 29 tmp = 10*tmp + (buf[i]-‘0‘); 30 tmp %= phi; 31 } 32 tmp += phi; 33 tmp = power2(tmp); 34 printf("%I64d\n", tmp); 35 } 36 37 return 0; 38 }
原文:http://www.cnblogs.com/bombe1013/p/3864198.html