无论是找规律还是推答案都比较简单,推荐大家看一下这个博客:http://blog.csdn.net/queuelovestack/article/details/47321795
讲解的非常清楚,得到答案以后快速幂即可。
1 #include <iostream> 2 using namespace std; 3 4 typedef long long ll; 5 const int MOD = 1000000007; 6 7 ll pow_mod( ll a, ll n ) 8 { 9 ll res = 1; 10 while ( n ) 11 { 12 if ( n & 1 ) 13 { 14 res = res * a % MOD; 15 } 16 a = a * a % MOD; 17 n >>= 1; 18 } 19 return ( res - 1 + MOD ) % MOD; 20 } 21 22 int main () 23 { 24 ll t; 25 cin >> t; 26 while ( t-- ) 27 { 28 ll n; 29 cin >> n; 30 cout << pow_mod( 2, n - 1 ) << endl; 31 } 32 return 0; 33 }