快速幂 a的b次方对c取模

2019-04-13 15:14发布

  #include #include #include #include using namespace std; #define N 500 long long Pow(long long a, long long b, long long c) { long long ans = 1; a %= c; while(b) { if(b % 2 == 1) ans = (ans * a) % c; a = (a * a) % c; b /= 2; } return ans; } int main() { int t; long long n, num; scanf("%d", &t); while(t--) { scanf("%lld", &n); num = Pow(2, n - 1, 1000000007); printf("%lld ", num - 1); } return 0; }