You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
506 B
C++
24 lines
506 B
C++
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
using ll = long long;
|
|
ll mod = 1e9 + 7;
|
|
ll qpow(ll a, ll b)
|
|
{
|
|
ll ans = 1;
|
|
for (; b; b >>= 1, a = a * a % mod)
|
|
if (b & 1)
|
|
ans = ans * a % mod;
|
|
return ans;
|
|
}
|
|
ll inv(ll x) { return qpow(x, mod - 2); }
|
|
int main()
|
|
{
|
|
ios::sync_with_stdio(false), cin.tie(nullptr);
|
|
ll T, n, m;
|
|
cin >> T;
|
|
while (T--)
|
|
{
|
|
cin >> n >> m;
|
|
cout << (qpow(qpow(2, n) - 1, m - 1) * 2 + (n & 1)) * inv(3) % mod << endl;
|
|
}
|
|
} |