#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define MOD 1000000007
#define ll long long int
#define fr(i, a, b) for (int i = a; i < b; i++)
inline int binaryExponentiation(ll base, int exp, int mod = MOD) {
ll result = 1;
while (exp) {
if (exp & 1) result = (result * base) % mod;
base = (base * base) % mod;
exp >>= 1;
}
return (int)result;
}
void solve() {
int n;
cin >> n;
ll answer = 0;
fr(i, 1, n) {
ll current = binaryExponentiation(2, n - i - 1);
current = (2 * current * (n - i)) % MOD;
current = (current * i) % MOD;
current = (current * i) % MOD;
answer = (answer + current) % MOD;
}
cout << answer << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) solve();
return 0;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter