text stringlengths 49 983k |
|---|
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
long long dp[3];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
long long t;
cin >> t;
long long n[t];
for (long long i = (0); i < (t); i++) cin >> n[i];
map<long long, long long> ans;
for (long long i = (0); i < (t); i++) ans[n[i]] = -1;
for (long long i = (1); i <= (2000000); i++) {
if (i <= 2) {
dp[i] = 0;
} else {
dp[i % 3] = dp[(i - 1) % 3] + 2 * dp[(i - 2) % 3];
if (i % 3 == 0) dp[i % 3] += 4;
dp[i % 3] %= MOD;
}
if (ans.find(i) != ans.end()) {
ans[i] = dp[i % 3];
}
}
for (long long i = (0); i < (t); i++) {
cout << (ans[n[i]]) << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
const int INF = 0x7FFFFFFF;
template <class T>
inline bool checkmin(T &a, T b) {
return b < a ? a = b, 1 : 0;
}
template <class T>
inline bool checkmax(T &a, T b) {
return b > a ? a = b, 1 : 0;
}
template <class T>
inline T sqr(T x) {
return x * x;
}
template <class T>
inline bool bit(T a, int b) {
return (a >> b) & 1;
}
inline int popcount(int n) { return __builtin_popcount(n); }
inline int popcount(long long n) { return __builtin_popcountll(n); }
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << '{';
string sep;
for (const auto &x : v) os << sep << x, sep = ", ";
return os << '}';
}
constexpr bool local = false;
template <int m, typename intbase = int>
struct ModInt {
intbase r;
ModInt() : r(0) {}
ModInt(int64_t rr) : r(rr) {
if (abs(r) >= m) r %= m;
if (r < 0) r += m;
}
ModInt(int rr) : r(rr) {
if (abs(r) >= m) r %= m;
if (r < 0) r += m;
}
ModInt inv() const { return this->pow(m - 2); }
template <typename I>
ModInt pow(I t) const {
ModInt ret(1), base(*this);
while (t) {
if (t & 1) ret *= base;
base *= base;
t >>= 1;
}
return ret;
}
ModInt operator*(const ModInt &t) const { return (int64_t(r) * t.r) % m; }
ModInt operator/(const ModInt &t) const { return *this * t.inv(); }
ModInt operator+=(const ModInt &t) {
r += t.r;
if (r >= m) r -= m;
return *this;
}
ModInt operator-=(const ModInt &t) {
r -= t.r;
if (r < 0) r += m;
return *this;
}
friend std::ostream &operator<<(std::ostream &os, ModInt x) {
return os << x.r;
}
ModInt operator+(const ModInt &t) const { return ModInt(*this) += t; }
ModInt operator-(const ModInt &t) const { return ModInt(*this) -= t; }
ModInt operator-() const { return ModInt(m - r); }
ModInt operator*=(const ModInt &t) { return *this = *this * t; }
ModInt operator/=(const ModInt &t) { return *this = *this / t; }
bool operator==(const ModInt &t) const { return r == t.r; }
bool operator!=(const ModInt &t) const { return r != t.r; }
};
using Int = ModInt<int(1e9 + 7)>;
struct Mat {
Int a[3][3] = {};
};
Mat operator*(const Mat &a, const Mat &b) {
Mat ret;
for (int i = 0; i < (int)3; i++)
for (int j = 0; j < (int)3; j++)
for (int k = 0; k < (int)3; k++) {
ret.a[i][j] += a.a[i][k] * b.a[k][j];
};
return ret;
}
Mat get_one() {
Mat ret;
for (int i = 0; i < (int)3; i++)
for (int j = 0; j < (int)3; j++) ret.a[i][j] = i == j;
return ret;
}
Mat one = get_one();
Mat pow(Mat base, int t) {
Mat ret = one;
while (t) {
if (t & 1) ret = ret * base;
base = base * base;
t >>= 1;
}
return ret;
}
const int N = 2e6 + 10;
Int ans[2000005][2];
bool vis[2000005];
Int getmax(int k) {
if (k % 3 == 0) return ans[k][0];
return ans[k][1];
}
int main() {
ans[3][0] = 1;
ans[4][0] = 1;
ans[4][1] = 1;
for (int i = 5; i < N; i++) {
ans[i][0] = ans[i - 1][1] + ans[i - 2][1] * Int(2) + Int(1);
ans[i][1] = getmax(i - 1) + getmax(i - 2) * 2;
}
for (int i = 0; i < (int)40; i++) {
;
}
int T;
cin >> T;
for (int cas = 0; cas < (int)T; cas++) {
int n;
cin >> n;
cout << getmax(n) * Int(4) << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXM = 2000001;
long long int arr[MAXM];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
arr[1] = 0;
arr[2] = 0;
arr[3] = 1;
for (int i = 4; i < MAXM; i++) {
arr[i] = ((arr[i - 1] + 2 * arr[i - 2]) % 1000000007);
if (i % 3 == 0) arr[i] = (arr[i] + 1) % 1000000007;
}
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
cout << (arr[n] * 4) % 1000000007 << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long ans[2000010];
bool root[2000010];
int n, t;
int main() {
cin >> t;
ans[3] = 4;
ans[4] = 4;
root[3] = 1;
for (int i = 3; i <= 2000000; i++) {
ans[i] = ans[i - 1] + 2 * ans[i - 2];
if (root[i - 1] == 0 && root[i - 2] == 0) {
root[i] = 1;
ans[i] += 4;
}
ans[i] %= 1000000007;
}
while (t--) {
cin >> n;
cout << ans[n] << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 50;
const int Mod = 1e9 + 7;
long long T, n, cnt[maxn], vis[maxn];
void Init() {
vis[1] = vis[2] = 0;
cnt[1] = cnt[2] = 0;
for (int i = 3; i <= maxn - 10; i++) {
cnt[i] = (cnt[i - 1] + cnt[i - 2] * 2) % Mod;
if (!vis[i - 1] && !vis[i - 2])
cnt[i]++, vis[i] = 1;
else
vis[i] = 0;
}
}
int main() {
Init();
cin >> T;
while (T--) {
cin >> n;
if (n <= 2)
cout << "0" << endl;
else
cout << cnt[n] * 4 % Mod << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
const int inf = 1034567891;
const long long LL_INF = 1234567890123456789ll;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
template <typename T>
T GCD(T a, T b) {
long long t;
while (a) {
t = a;
a = b % a;
b = t;
}
return b;
}
template <typename T>
string toString(T a) {
return to_string(a);
}
template <typename T>
void toInt(string s, T& x) {
stringstream str(s);
str >> x;
}
inline int add(int x, int y) {
x += y;
if (x >= mod) x -= mod;
return x;
}
inline int sub(int x, int y) {
x -= y;
if (x < 0) x += mod;
return x;
}
inline int mul(int x, int y) { return (x * 1ll * y) % mod; }
inline int powr(int a, long long b) {
int x = 1 % mod;
while (b) {
if (b & 1) x = mul(x, a);
a = mul(a, a);
b >>= 1;
}
return x;
}
inline int inv(int a) { return powr(a, mod - 2); }
const int N = 2e6 + 5;
int dp[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
dp[3] = 1;
for (int i = 4; i < N; i++) {
dp[i] = add(dp[i - 1], mul(2, dp[i - 2]));
dp[i] = add(dp[i], (i % 3 == 0 ? 1 : 0));
}
int test;
cin >> test;
while (test--) {
int n;
cin >> n;
cout << mul(4, dp[n]) << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long module = 1e9 + 7;
const long int full = 2e6 + 5;
long long f[full];
long long b[full];
void solve() {}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
f[1] = f[2] = 0;
f[3] = f[4] = 1;
b[1] = b[2] = 0;
b[3] = b[4] = 1;
for (int i = 5; i <= 2000000; i++) {
b[i] = b[i - 1] + 2 * b[i - 2] % module;
f[i] = b[i] + f[i - 3] % module;
}
int t, x;
cin >> t;
for (; t--;) {
cin >> x;
cout << f[x] * 4 % module << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
mt19937 rd(chrono ::steady_clock ::now().time_since_epoch().count());
long long Rand(long long l, long long h) { return l + rd() % (h - l + 1); }
template <typename T>
inline void read(T &x) {
register char c;
bool sign = 0;
for (c = getchar(); !isdigit(c); c = getchar())
if (c == '-') sign = !sign;
x = c - '0';
for (c = getchar(); isdigit(c); c = getchar()) x = x * 10 + c - '0';
if (sign) x = -x;
}
template <typename T>
inline bool mini(T &x, T y) {
if (x > y)
x = y;
else
return 0;
return 1;
}
template <typename T>
inline bool maxi(T &x, T y) {
if (x < y)
x = y;
else
return 0;
return 1;
}
template <typename T>
inline void _abs(T &x) {
if (x < 0) x = -x;
return;
}
const int N = 2e6 + 6;
const long long mod = 1e9 + 7;
long long n;
long long f[N], g[N];
long long res[N];
int main() {
ios ::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
f[1] = 1;
f[2] = 1;
for (int i = 3; i < N; ++i) {
f[i] = (f[i - 1] + f[i - 2] * 2 % mod) % mod;
g[i] = f[i - 2];
res[i] = (res[i - 3] + g[i] * 4 % mod) % mod;
}
int t;
cin >> t;
while (t--) {
cin >> n;
cout << res[n] << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int ar[2000005];
char ch[2000005];
long long re[2000005];
int n, m, k, ii;
long long add(long long a, long long b) {
return (a + b) >= 1000000007 ? a + b - 1000000007 : a + b;
}
long long mul(long long a, long long b) { return (a * b) % 1000000007; }
void solve() {
scanf("%d", &n);
printf("%lld\n", (re[n] * 4) % 1000000007);
}
int main() {
int t = 1;
re[3] = 1;
for (int i = 4; i <= 2000005 - 3; i++) {
re[i] = add(mul(2, re[i - 2]), re[i - 1]) + (i % 3 == 0);
}
scanf("%d", &t);
while (t--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7, N = 2e6 + 9;
long long f[N];
int32_t main() {
ios::sync_with_stdio(0), cin.tie(0);
f[3] = f[4] = 4;
for (long long i = 5; i < N; i++) {
f[i] = (f[i - 1] + 2 * f[i - 2] % mod) % mod;
if (i % 3 == 0) f[i] = (f[i] + 4) % mod;
}
long long T;
cin >> T;
while (T--) {
long long n;
cin >> n;
cout << f[n] << "\n";
}
}
|
#include <bits/stdc++.h>
namespace {
template <typename T>
void print(const T& v) {
std::cout << v << '\n';
}
template <typename... T>
void answer(T&&... args) {
(print(std::forward<T>(args)), ...);
}
} // namespace
constexpr size_t N = 2e6 + 1;
constexpr unsigned long long M = 1000000007;
unsigned long long x[N + 1];
bool initialize() {
for (size_t i = 2; i <= N; ++i)
x[i] = (2 * x[i - 2] + x[i - 1] + (i % 3 ? 0 : 4)) % M;
return true;
}
void solve(size_t n) {
static bool _ = initialize();
answer(x[n]);
}
void test_case() {
size_t n;
std::cin >> n;
solve(n);
}
int main() {
size_t t;
std::cin >> t;
while (t-- > 0) test_case();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int len = 2 * 1e6 + 1;
int mod = 1e9 + 7;
vector<long long> a(len);
vector<bool> b(len);
a[3] = 4;
b[3] = true;
for (int i = 4; i < len; i++) {
a[i] = 2 * a[i - 2] + a[i - 1];
if (!b[i - 1] && !b[i - 2]) {
a[i] += 4;
b[i] = true;
}
a[i] = a[i] % mod;
}
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int t;
cin >> t;
cout << a[t] << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = std::pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vs = vector<string>;
template <typename T>
void output_vector(const vector<T>& v, int start = -1, int end = -1) {
if (start < 0) start = 0;
if (end < 0) end = int(v.size());
for (int i = start; i < end; i++) cout << v[i] << " ";
cout << endl;
}
int main() {
int t;
cin >> t;
vector<long long> answer(2 * 1e6 + 1, 0);
for (int j = 3; j < answer.size(); j++) {
answer[j] = (2 * answer[j - 2]) + answer[j - 1];
if (j % 3 == 0) answer[j] += 4;
answer[j] %= 1000000007;
}
for (int i = 0; i < t; i++) {
long long n;
cin >> n;
cout << answer[n] << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int size = 2e6 + 7;
int arr[size];
void fill() {
long long a = 1, b = 0, c = 0;
for (int i = 2; i < size; i++) {
b = a;
a += c * 2 + (i % 3 == 1);
c = b;
a %= 1000000007;
arr[i + 1] = (b * 4) % 1000000007;
}
}
int solve() {
int n;
cin >> n;
if (n < 3) return 0;
return arr[n];
}
int main() {
ios_base::sync_with_stdio(0);
fill();
short t;
cin >> t;
while (t--) cout << solve() << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<long long> dp(2000000 + 1);
void prepare() {
dp[1] = 0;
dp[0] = 0;
for (int i = 2; i <= 2000000; i++) {
dp[i] = dp[i - 1] + 2 * dp[i - 2];
if (i % 3 == 0) {
dp[i] += 4;
}
dp[i] %= 1000000000 + 7;
}
}
void solver() {
long long n;
cin >> n;
cout << dp[n];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
prepare();
cin >> t;
while (t--) {
solver();
cout << endl;
}
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const double PI = atan(1.0) * 4;
const int di[4] = {-1, 0, 1, 0};
const int dj[4] = {0, -1, 0, 1};
const long long INF = (long long)2e18 + 50;
const int maximum = numeric_limits<int>::min();
const int minimum = numeric_limits<int>::max();
constexpr int N = 2e6, P = 1000000007;
int a[N + 1], b[N + 1];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
for (int i = 1; i <= N; ++i) {
a[i] = (2ll * a[i - 2] + a[i - 1]) % P;
if (b[i - 1] && b[i - 2]) {
a[i] = (a[i] + 1) % P;
} else {
b[i] = 1;
}
}
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
cout << 4ll * a[n] % P << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long p) {
long long ans = 1;
while (p) {
if (p & 1) ans *= a;
p /= 2;
a *= a;
ans %= mod;
a %= mod;
}
return ans;
}
long long mdinv(long long a) { return powmod(a, mod - 2); }
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
vector<vector<long long> > dp(2000001, vector<long long>(2));
dp[3][1] = 4;
for (int i = 4; i <= 2000000; i++) {
dp[i][1] = 4 + dp[i - 1][0] + 2 * dp[i - 2][0];
dp[i][1] %= mod;
dp[i][0] =
2 * max(dp[i - 2][1], dp[i - 2][0]) + max(dp[i - 1][1], dp[i - 1][0]);
dp[i][0] %= mod;
}
int t;
cin >> t;
while (t--) {
int lev;
cin >> lev;
cout << max(dp[lev][1], dp[lev][0]) << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 1;
const int MAXN = 2e6 + 5;
const int mod = 1e9 + 7;
long long lol(int a, int b) {
if (a >= b) return a - b;
return a + mod - b;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
vector<vector<long long>> dp(MAXN, vector<long long>(2));
dp[1][0] = dp[1][1] = 0;
dp[2][0] = dp[2][1] = 0;
for (int i = 3; i < MAXN; i++) {
dp[i][0] = (2 * dp[i - 2][1] + dp[i - 1][1]) % mod;
long long kek =
2 * lol(dp[i - 2][1], dp[i - 2][0]) + lol(dp[i - 1][1], dp[i - 1][0]);
if (kek >= 4)
dp[i][1] = dp[i][0];
else
dp[i][1] = (dp[i][0] + 4 - kek) % mod;
}
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
cout << dp[n][1] << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int vertices[2000005][3];
int ans[2000005];
int main() {
vertices[1][0] = 1;
for (int i = 2; i <= 2000002; i++) {
vertices[i][0] =
((2ll * vertices[i - 1][1]) % 1000000007 + vertices[i - 1][0]) %
1000000007;
vertices[i][1] = vertices[i - 1][0];
vertices[i][2] = (vertices[i - 1][2] + vertices[i - 1][1]) % 1000000007;
}
ans[1] = ans[2] = 0;
for (int i = 3; i <= 2000002; i++) {
ans[i] = (ans[i - 3] + vertices[i - 1][1]) % 1000000007;
}
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
printf("%d\n", (4ll * ans[n]) % 1000000007);
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long dp[2000005];
int main() {
long long mod = 1e9 + 7;
dp[0] = 0, dp[1] = 0, dp[2] = 0;
for (int i = 3; i <= 2000000; i++) {
dp[i] = (dp[i - 1] + 2 * dp[i - 2] + 4 * (i % 3 == 0)) % mod;
}
int t;
cin >> t;
for (int tc = 0; tc < t; tc++) {
int n;
cin >> n;
cout << dp[n] << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<long long> dp(2000009);
int main() {
long long t;
cin >> t;
dp[3] = 1;
for (int i = 4; i < 2000009; i++) {
dp[i] = (dp[i - 1] + 2 * dp[i - 2]) % 1000000007;
if (i % 3 == 0) {
dp[i] += 1;
dp[i] %= 1000000007;
}
}
while (t--) {
long long n;
cin >> n;
cout << (dp[n] * 4) % 1000000007 << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6;
const long long MOD = 1e9 + 7;
long long ans[N + 10];
bool used[N + 10];
int main() {
ans[1] = 0;
ans[2] = 0;
for (int i = 3; i <= N; i++) {
if (!used[i - 1] && !used[i - 2]) {
ans[i] = ans[i - 2] * 2 % MOD + ans[i - 1] + 1;
ans[i] %= MOD;
used[i] = true;
} else {
ans[i] = ans[i - 2] * 2 % MOD + ans[i - 1];
ans[i] %= MOD;
}
}
int T;
scanf("%d", &T);
while (T--) {
int n;
scanf("%d", &n);
printf("%lld\n", ans[n] * 4 % MOD);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int T = 0;
long long int dp[4][2000003];
int main() {
dp[0][1] = 1;
dp[1][1] = 0;
dp[2][1] = 0;
dp[3][1] = 0;
for (int i = 1; i < 2000001; i++) {
dp[0][i + 1] =
((dp[0][i] % 1000000007) + (dp[1][i] * 2) % 1000000007) % 1000000007;
dp[1][i + 1] = dp[0][i];
dp[2][i + 1] = (dp[1][i] % 1000000007 + dp[2][i] % 1000000007) % 1000000007;
if (i != 1 && i != 2)
dp[3][i] = ((dp[1][i - 1] * 4) % 1000000007 + dp[3][i - 3] % 1000000007) %
1000000007;
}
cin >> T;
while (T--) {
int N;
cin >> N;
cout << dp[3][N] << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 7;
const long long INFLONG = (long long)1e18 + 7;
const double EPS = 1e-9;
template <typename T>
T sqr(T a) {
return a * a;
}
vector<int> d;
void precalc(vector<int>& d, int n) {
d.resize(n + 10, 0);
d[3] = 1;
d[4] = 1;
for (int i = 5; i <= n; i++) {
d[i] = (((i % 3 == 0) ? 1LL : 0LL) + (long long)(d[i - 1]) % INF +
d[i - 2] * 2LL % INF) %
INF;
}
}
void solve() {
int n;
scanf("%d", &n);
printf("%d\n", (int)((d[n] * 4LL) % INF));
}
int main() {
srand(time(0));
int T = 1;
scanf("%d", &T);
precalc(d, 2000000);
while (T--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
const int mod = int(1e9 + 7);
const int MN = int(2e6 + 7);
using namespace std;
int main() {
int t;
cin >> t;
vector<long long int> dp(MN, 0);
dp[1] = 0;
dp[2] = 0;
dp[3] = 4;
for (int i = 4; i <= MN; i++) {
long long w = (2 * dp[i - 2]) + (dp[i - 1]) + (i % 3 == 0 ? 4 : 0);
dp[i] = w % mod;
}
while (t--) {
int n;
cin >> n;
cout << dp[n] << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
long long int t, n, m, a[2000005] = {0};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
long long int i, j, k, x, y;
a[3] = a[4] = 4;
for (i = 5; i < 2000005; i++) {
a[i] = a[i - 1] + (2 * a[i - 2]);
if (i % 3 == 0) a[i] += 4;
a[i] %= mod;
}
cin >> t;
while (t--) {
cin >> n;
cout << a[n] << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<long long> v(2e6 + 7);
v[0] = v[1] = 0;
v[2] = 4;
for (int i = 3; i < 2e6 + 7; i++) {
long long w = v[i - 1];
w += 2 * v[i - 2] + (i % 3 == 2) * 4;
w %= (long long)1e9 + 7;
v[i] = w;
}
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
n--;
cout << v[n] % (long long)(1e9 + 7) << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long nodes[2000001], m0[2000001], m1[2000001], m2[2000001];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
nodes[1] = 1;
nodes[2] = 1;
for (int i = 3; i < 2000001; i++)
nodes[i] = (nodes[i - 1] + nodes[i - 2] * 2) % mod;
for (int i = 1; i < 2000001; i++) {
m0[i] = (m0[i] + m0[i - 1]) % mod;
m1[i] = (m1[i] + m1[i - 1]) % mod;
m2[i] = (m2[i] + m2[i - 1]) % mod;
if (i % 3 == 1)
m1[i] += nodes[i];
else if (i % 3 == 2)
m2[i] += nodes[i];
else
m0[i] += nodes[i];
}
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
if (n <= 2) {
cout << "0" << endl;
continue;
}
n -= 2;
if (n % 3 == 1)
cout << (m1[n] * 4) % mod << endl;
else if (n % 3 == 2)
cout << (m2[n] * 4) % mod << endl;
else
cout << (m0[n] * 4) % mod << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int maxn = 2e6 + 5;
constexpr int mod = 1e9 + 7;
int t, n;
ll F[maxn], G[maxn];
inline void init() {
F[1] = F[2] = 0;
G[1] = G[2] = 0;
for (int i = 3; i <= 2e6; ++i) {
G[i] = (F[i - 1] + 2 * F[i - 2]) % mod;
F[i] = max(1 + G[i - 1] + 2 * G[i - 2], F[i - 1] + 2 * F[i - 2]) % mod;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
init();
cin >> t;
while (t--) {
cin >> n;
cout << 4 * F[n] % mod << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long t, n, s[2000001], f[2000001], m = 1000000007;
void dp() {
s[1] = 1;
s[2] = 1;
f[1] = 1;
f[2] = 1;
for (int i = 3; i < 2000001; i++) s[i] = (s[i - 2] * 2 + s[i - 1]) % m;
for (int i = 3; i < 2000001; i++) f[i] = (f[i - 3] + s[i]) % m;
}
int main() {
scanf("%d", &t);
dp();
while (t--) {
scanf("%d", &n);
if (n <= 2)
printf("0\n");
else
printf("%lld\n", (4 * f[n - 2]) % m);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, dp[2000005], t;
long long Mod = 1e9 + 7;
int main() {
dp[0] = dp[1] = 0;
dp[2] = 4;
for (int i = 3; i <= 2000000; i++) {
long long w = dp[i - 1];
w += 2 * dp[i - 2] + (i % 3 == 2) * 4;
w %= Mod;
dp[i] = w;
}
cin >> t;
while (t--) {
cin >> n;
n--;
cout << dp[n] << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
const unsigned long long INF = 1e18;
const int N = 2 * 1e6;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
vector<long long> dp(N + 1);
dp[0] = 0;
dp[1] = 0;
dp[2] = 0;
for (int i = 3; i <= N; i++) {
dp[i] = (dp[i - 1] % M + (dp[i - 2] * 2) % M) % M;
if (i % 3 == 0) dp[i] = (dp[i] + 1) % M;
}
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int ans = (dp[n] * 4) % M;
cout << ans << "\n";
}
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 2e6 + 5, mod = 1e9 + 7;
int add(int a, int b) { return (a + b) % mod; }
int mul(int a, int b) { return (1ll * a * b) % mod; }
int t, n, dp[N];
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
for (int i = 3; i < N; i++)
dp[i] = add(add(dp[i - 1], mul(2, dp[i - 2])), (i % 3 == 0));
cin >> t;
while (t--) {
cin >> n;
cout << mul(4, dp[n]) << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e6 + 7;
const int mod = 1e9 + 7;
long long int dp[maxn] = {0};
int main() {
int t;
cin >> t;
dp[1] = 0;
dp[2] = 0;
dp[3] = 1;
for (int i = 4; i < maxn; i++) {
dp[i] = 2 * dp[i - 2] + dp[i - 1];
if (i % 3 == 0) dp[i]++;
dp[i] %= mod;
}
while (t--) {
int n;
cin >> n;
cout << (dp[n] * 4 + mod) % mod << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int_fast64_t modulo = 1000000007;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
using tuple_t = tuple<int_fast64_t, int_fast64_t, int_fast64_t, int_fast64_t>;
vector<tuple_t> d(2000001);
get<0>(d[1]) = 1;
for (size_t i = 2; i < d.size(); ++i) {
get<0>(d[i]) = (get<0>(d[i - 1]) + 2 * get<1>(d[i - 1])) % modulo;
get<1>(d[i]) = get<0>(d[i - 1]);
get<2>(d[i]) = (get<1>(d[i - 1]) + get<2>(d[i])) % modulo;
get<3>(d[i]) = get<1>(d[i - 1]);
if (i >= 3) {
get<3>(d[i]) += get<3>(d[i - 3]);
get<3>(d[i]) %= modulo;
}
}
size_t T;
cin >> T;
for (size_t t = 0; t < T; ++t) {
int_fast64_t n;
cin >> n;
cout << 4 * get<3>(d[n]) % modulo << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 2000010, M = 1010, mod = 1e9 + 7;
int T, n;
int f[N];
int main() {
f[1] = f[2] = 0;
for (int i = 3; i < N; i++)
f[i] = (long long)((2LL * f[i - 2] + f[i - 1]) % mod + 4LL * (i % 3 == 0)) %
mod;
cin >> T;
while (T--) {
cin >> n;
cout << f[n] << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
vector<long long> v(2e6 + 10);
v[3] = 4;
for (int i = 4; i < v.size(); i++) {
v[i] = v[i - 1] + 2 * v[i - 2] + (i % 3 == 0 ? 4 : 0);
v[i] %= mod;
}
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
printf("%lld\n", v[n]);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int test, n;
long long f[2000001][2];
const int P = 1000000007;
int main() {
memset(f, 0, sizeof(f));
f[3][0] = 0;
f[3][1] = 4;
for (int i = 4; i <= 2000000; i++)
f[i][0] = max(f[i - 1][0], f[i - 1][1]) + max(f[i - 2][0], f[i - 2][1]) * 2,
f[i][0] %= P, f[i][1] = 4 + f[i - 1][0] + 2 * f[i - 2][0], f[i][1] %= P;
scanf("%d", &test);
for (; test--;) {
scanf("%d", &n);
printf("%lld\n", max(f[n][0], f[n][1]));
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2000000;
const long long MOD = 1000000007;
long long t, n;
long long dp[MAXN + 1][2];
long long ans[MAXN + 1];
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
dp[1][0] = 1;
for (long long i = 2; i <= MAXN; i++) {
dp[i][0] = (dp[i - 1][0] + dp[i - 1][1] * 2) % MOD;
dp[i][1] = (dp[i - 1][0]) % MOD;
ans[i] = (dp[i - 1][1] * 4 + (i >= 3 ? ans[i - 3] : 0)) % MOD;
}
cin >> t;
while (t--) {
cin >> n;
cout << ans[n] << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long LINF = 1e18;
const int INF = 0x3f3f3f3f;
const int MAXN = 2000050;
long long ans[MAXN];
void init() {
for (int i = 3; i <= MAXN; i++) {
ans[i] = ans[i - 1] + 2 * ans[i - 2];
if (i % 3 == 0) ans[i] += 4;
ans[i] %= MOD;
}
}
void solve(int T) {
int n;
scanf("%d", &n);
printf("%lld\n", ans[n]);
}
signed main() {
int t = 1;
init();
scanf("%d", &t);
for (int i = 1; i <= t; i++) {
solve(i);
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int MAXN = 1e6 + 1e6 + 1;
long long p = 1e9 + 7;
vector<long long> v1(MAXN), s1(MAXN), a1(MAXN);
vector<long long> v0(MAXN), s0(MAXN), a0(MAXN), f(MAXN);
v1[1] = 1;
f[1] = 1;
for (int i = 2; i < MAXN; ++i) {
v1[i] = (v0[i - 1] + 2 * s0[i - 1]) % p;
s1[i] = v1[i - 1];
a1[i] = (a1[i - 1] + s1[i - 1]) % p;
v0[i] = (v1[i - 1] + 2 * s1[i - 1]) % p;
s0[i] = v0[i - 1];
a0[i] = (a0[i - 1] + s0[i - 1]) % p;
if (i >= 3) {
f[i] = (f[i - 3] + v0[i] + v1[i]) % p;
} else {
f[i] = 1;
}
}
int t;
cin >> t;
for (int i = 0; i < t; ++i) {
int n;
cin >> n;
if (n < 3) {
cout << 0 << endl;
} else {
n = n - 2;
cout << (f[n] * 4) % p << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long dp[2000006];
void init() {
dp[1] = 0, dp[2] = 0, dp[3] = 1;
for (int i = 4; i < 2000006; i++) {
if (i % 3 == 0) {
dp[i] = (2 * dp[i - 2] + dp[i - 1] + 1) % mod;
} else
dp[i] = (2 * dp[i - 2] + dp[i - 1]) % mod;
}
}
int main() {
init();
int t, n;
scanf("%d", &t);
for (int i = 1; i <= t; i++) {
scanf("%d", &n);
cout << 4 * dp[n] % mod << endl;
}
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const int MOD = 1e9 + 7;
const int mxN = 2e6 + 3;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int nT = 1;
cin >> nT;
int ans[mxN];
ans[0] = 0;
ans[1] = 0;
ans[2] = 0;
long long prev_zero = 1;
long long prev_one = 1;
for (int i = 3; i < mxN; ++i) {
long long cur_zero = (2 * prev_one) + prev_zero;
cur_zero %= MOD;
long long cur_one = prev_zero;
cur_one %= MOD;
long long nw = (prev_one * 4) + (long long)ans[i - 3];
nw %= MOD;
ans[i] = (int)nw;
prev_zero = cur_zero;
prev_one = cur_one;
}
for (int i = 1; i <= nT; ++i) {
int tt;
cin >> tt;
cout << ans[tt] << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void onScreen() {
freopen("test.in", "r", stdin);
freopen("test.out", "w", stdout);
}
const int NMAX = 3e6;
const int VMAX = 1e7 + 10;
const int MOD = 1e9 + 7;
int n;
int v[NMAX];
int dp[NMAX];
void read() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> v[i];
}
void solve() {
dp[1] = dp[2] = 0;
dp[3] = 4;
for (int i = 4; i < NMAX; i++) {
dp[i] = ((dp[i - 2] * 2) % MOD + dp[i - 1]) % MOD;
if (i % 3 == 0) {
dp[i] += 4;
dp[i] %= MOD;
}
}
for (int i = 1; i <= n; i++) cout << dp[v[i]] << "\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int q = 1;
while (q--) {
read();
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007, N = 2e6 + 5;
pair<long long, long long> dp[N];
void solve() {
long long n;
cin >> n;
cout << dp[n].first << '\n';
}
int32_t main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
dp[0].first = dp[1].first = dp[2].first = 0;
dp[3].first = 4;
dp[0].second = dp[1].second = dp[2].second = 0;
dp[3].second = 1;
for (long long i = (long long)4; i < N; i++) {
dp[i].first = (2 * dp[i - 2].first + dp[i - 1].first) % MOD;
dp[i].second = ((2 * dp[i - 2].second + dp[i - 1].second) > 0 ? 0 : 1);
if (dp[i].second == 1) dp[i].first += 4;
}
long long t = 1;
cin >> t;
while (t--) solve();
}
|
#include <bits/stdc++.h>
using namespace std;
int N;
long long dp[2000005][2];
void pre() {
memset(dp, -1, sizeof(dp));
for (int i = 1; i <= 2; i++) dp[i][0] = dp[i][1] = 0;
dp[3][0] = 1;
dp[3][1] = 0;
dp[4][0] = 1, dp[4][1] = 1;
for (int i = 5; i <= 2000000; i++) {
dp[i][1] = 2 * dp[i - 2][0] + dp[i - 1][0];
dp[i][0] = max(dp[i][1], 1 + 2 * dp[i - 2][1] + dp[i - 1][1]);
dp[i][1] %= 1000000007;
dp[i][0] %= 1000000007;
}
}
int main() {
pre();
int T;
cin >> T;
while (T--) {
int x;
cin >> x;
cout << dp[x][0] * 4 % 1000000007 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
mt19937 gen(time(0));
bool IS_ONE_TEST = 0;
long long maxn = 2000005;
vector<long long> c1(maxn), c2(maxn), c3(maxn);
vector<long long> ans(maxn);
void init() {
long long n;
n = maxn;
long long mod = 1e9 + 7;
c1[1] = 1;
c1[2] = 1;
c2[2] = 1;
for (int i = 3; i <= n; ++i) {
c3[i] = c2[i - 1];
c2[i] = c1[i - 1];
c1[i] = (c3[i] * 2 + c2[i]) % mod;
}
for (int i = 0; i <= n; ++i) {
ans[i] = (c3[i] * 4 + (i >= 3 ? ans[i - 3] : 0)) % mod;
}
}
void solve() {
long long n;
cin >> n;
cout << ans[n] << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout << fixed << setprecision(15);
long long t;
if (IS_ONE_TEST)
t = 1;
else
cin >> t;
init();
while (t-- > 0) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
int dp[2000001];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tc, n;
cin >> tc;
dp[1] = 0, dp[2] = 0, dp[3] = 4, dp[4] = 4;
for (int i = 5; i <= 2000000; i++)
dp[i] = ((2 * dp[i - 2]) % 1000000007 + dp[i - 1] % 1000000007 +
(i % 3 == 0 ? 4 : 0)) %
1000000007;
while (tc--) {
cin >> n;
cout << dp[n] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e6 + 7, M = 1e9 + 7;
long long f0[N], f1[N], a[3], r[N];
long long tt, i, j;
int main() {
f0[1] = 1;
f1[1] = 0;
a[1] = 0;
for (i = 2; i < N; i++) {
f0[i] = (f0[i - 1] + (f1[i - 1] * 2) % M) % M;
f1[i] = f0[i - 1];
j = i % 3;
a[j] = (a[j] + f1[i - 1]) % M;
r[i] = a[j];
}
cin >> tt;
while (tt--) {
cin >> i;
cout << (r[i] * 4) % M << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long INF(0x3f3f3f3f3f3f3f3fll);
const int inf(0x3f3f3f3f);
const int N = 2e6 + 10, MOD = 1e9 + 7;
int dx[4] = {0, -1, 0, 1}, dy[4] = {-1, 0, 1, 0};
int dx8[8] = {0, 0, 1, -1, -1, -1, 1, 1}, dy8[8] = {1, -1, 0, 0, -1, 1, -1, 1};
int t, n;
long long f[N][2];
long long ans;
void solve() { memset(f, 0, sizeof(f)); }
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
;
cin >> t;
solve();
f[1][0] = f[1][1] = 0;
f[2][0] = f[2][1] = 0;
f[3][0] = 0, f[3][1] = 4;
f[4][0] = 4, f[4][1] = 4;
f[5][0] = 12, f[5][1] = 8;
for (int i = 6; i < N; i++) {
f[i][0] =
(2 * max(f[i - 2][0], f[i - 2][1]) + max(f[i - 1][0], f[i - 1][1])) %
MOD;
f[i][1] = (4 + 2 * f[i - 2][0] + f[i - 1][0]) % MOD;
}
while (t--) {
cin >> n;
ans = max(f[n][0], f[n][1]);
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
vector<string> vec_splitter(string s) {
s += ',';
vector<string> res;
while (!s.empty()) {
res.push_back(s.substr(0, s.find(',')));
s = s.substr(s.find(',') + 1);
}
return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
__attribute__((unused)) int idx,
__attribute__((unused)) int LINE_NUM) {
cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
if (idx > 0)
cerr << ", ";
else
cerr << "Line(" << LINE_NUM << ") ";
stringstream ss;
ss << H;
cerr << args[idx] << " = " << ss.str();
debug_out(args, idx + 1, LINE_NUM, T...);
}
double get_time() { return 1.0 * clock() / CLOCKS_PER_SEC; }
const int MAX = 2E6 + 100;
const int MOD = 1E9 + 7;
int main() {
vector<long long> dp1(MAX), dp2(MAX);
dp1[1] = 0, dp1[2] = 0;
dp2[1] = 0, dp2[2] = 0;
for (int i = 3; i < MAX; i++) {
dp1[i] = (4 + 2 * dp2[i - 2] + dp2[i - 1]) % MOD;
dp2[i] =
(max(dp1[i - 1], dp2[i - 1]) + 2 * max(dp1[i - 2], dp2[i - 2])) % MOD;
}
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
cout << max(dp1[n], dp2[n]) << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
namespace IO {
void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(), "w", stdout); }
void setIO(string s = "") {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
if (s.size()) {
setIn(s + ".inp");
setOut(s + ".out");
} else {
}
}
} // namespace IO
using namespace IO;
namespace Function {
template <typename T1, typename T2>
void amax(T1 &a, T2 b) {
assert(!(typeid(a).name() == typeid(int).name() &&
typeid(b).name() == typeid(long long).name()));
if (a < b) a = b;
}
template <typename T1, typename T2>
void amin(T1 &a, T2 b) {
if (a > b) a = b;
}
template <typename T>
void compress(T &a) {
sort(a.begin(), a.end());
a.resize(unique(a.begin(), a.end()) - a.begin());
}
template <typename T>
long long sqr(T x) {
return 1LL * x * x;
}
template <typename T1, typename T2>
long long gcd(T1 a, T2 b) {
return (b == 0 ? a : gcd(b, a % b));
}
template <typename T1, typename T2>
long long lcm(T1 a, T2 b) {
return 1LL * a / gcd(a, b) * b;
}
} // namespace Function
using namespace Function;
namespace Output {
void print(int x) { cout << x << "\n"; }
void print(unsigned int x) { cout << x << "\n"; }
void print(long unsigned int x) { cout << x << "\n"; }
void print(long long x) { cout << x << "\n"; }
void print(unsigned long long x) { cout << x << "\n"; }
void print(float x) { cout << x << "\n"; }
void print(double x) { cout << x << "\n"; }
void print(long double x) { cout << x << "\n"; }
void print(char x) { cout << x << "\n"; }
void print(char *x) { cout << x << "\n"; }
void print(unsigned char x) { cout << x << "\n"; }
void print(const char *x) { cout << x << "\n"; }
void print(string x) { cout << x << "\n"; }
void print(bool x) { cout << x << "\n"; }
template <class T, class... Ts>
void print(T t, Ts... ts) {
cout << t << " ";
print(ts...);
}
template <typename T1, typename T2>
void print(pair<T1, T2> a) {
print(a.first, a.second);
}
template <typename T>
void print(T a) {
for (auto it : a) {
print(it);
}
}
template <class T, class... Ts>
void prine(T t, Ts... ts) {
print(t, ts...);
exit(0);
}
} // namespace Output
using namespace Output;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
const int INF = 1e9;
const long long INFL = 1e18;
const int MOD = 1e9 + 7;
const int N = 2e6 + 10;
long long dp[N];
int main() {
setIO();
for (int i = 3; i < N; i++) {
dp[i] = (dp[i - 2] << 1) + dp[i - 1] + 4 * (i % 3 == 0);
dp[i] %= MOD;
}
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
print(dp[n]);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
while (a && b) a > b ? a %= b : b %= a;
return a + b;
}
long long a[2000010], i, T, x;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
for (i = 3; i <= 2e6; i++)
a[i] = (a[i - 1] + a[i - 2] * 2 + (i % 3 == 0) * 4) % 1000000007;
cin >> T;
while (T--) {
cin >> x;
cout << a[x] << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long dp[2000005];
int main() {
int t, n, i, j, k, T = 1;
long long ans;
for (i = 0; i < 2000005; i++) dp[i] = -1;
dp[0] = dp[1] = dp[2] = 0;
for (n = 3; n < 2000005; n++) {
dp[n] = (dp[n - 1] + dp[n - 2] * 2) % 1000000007;
if (n % 3 == 0) dp[n] = (dp[n] + 1) % 1000000007;
}
scanf("%d", &T);
for (t = 1; t <= T; t++) {
scanf("%d", &n);
ans = dp[n];
ans = (ans * 4) % 1000000007;
printf("%I64d", ans);
printf("\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long t, n, dp[2100000][2], ans;
int main() {
cin >> t;
for (int i = 3; i < 2000000 + 1; i++) {
dp[i][1] = dp[i - 1][0] + 2 * dp[i - 2][0] + 1;
dp[i][0] =
max(dp[i - 1][0], dp[i - 1][1]) + 2 * max(dp[i - 2][0], dp[i - 2][1]);
dp[i][1] = (dp[i][1] % 1000000007 + 1000000007) % 1000000007;
dp[i][0] = (dp[i][0] % 1000000007 + 1000000007) % 1000000007;
}
while (t--) {
cin >> n;
cout << (4 * max(dp[n][1], dp[n][0]) % 1000000007 + 1000000007) % 1000000007
<< "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int T = 0;
long long int dp[2000003];
long long int sol[2000003];
int main() {
dp[0] = 0;
dp[1] = 1;
dp[2] = 1;
dp[3] = 3;
sol[3] = 4;
for (long long int i = 4; i < 2000001; i++) {
dp[i] = ((dp[i - 2] * 2 % 1000000007) + dp[i - 1]) % 1000000007;
sol[i] = (sol[i - 3] + (dp[i - 2] * 4) % 1000000007) % 1000000007;
}
cin >> T;
while (T--) {
int N;
cin >> N;
cout << sol[N] << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
long long f[2000010];
long long sum[2000010];
void init() {
for (int i = 3; i <= 2e6; i++) {
f[i] = (2 * f[i - 2] + f[i - 1] + (i % 3 == 0)) % Mod;
}
}
void solve() {
int n;
scanf("%d", &n);
printf("%lld\n", f[n] * 4 % Mod);
}
int main() {
init();
int T;
scanf("%d", &T);
while (T--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)4e6 + 7;
const int INF = (int)10007;
const long long MOD = (long long)1e9 + 7;
long long dp[MAXN][2];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
dp[3][1] = 4;
for (int i = (int)4; i <= (int)2000000; i++) {
dp[i][0] =
max(dp[i - 1][0], dp[i - 1][1]) + 2 * max(dp[i - 2][0], dp[i - 2][1]);
dp[i][1] = dp[i - 1][0] + dp[i - 2][0] * 2 + 4;
dp[i][0] %= MOD;
dp[i][1] %= MOD;
}
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
cout << max(dp[n][0], dp[n][1]) << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int mod = int(1e9 + 7);
const int MN = int(2e6 + 7);
int dp[MN];
signed main() {
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
dp[0] = dp[1] = 0;
dp[2] = 4;
for (int i = 3; i < MN; i++) {
long long w = dp[i - 1];
w += 2 * dp[i - 2] + (i % 3 == 2) * 4;
w %= mod;
dp[i] = w;
}
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
n--;
cout << dp[n] % mod << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T>
void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
__print(t);
if (sizeof...(v)) cerr << ", ";
_print(v...);
}
const int RANDOM =
chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int random_int(int l, int r) {
return uniform_int_distribution<int>(l, r)(rng);
}
int range(int l, int r) { return l + rand() % (r - l + 1); }
void init(int argc, char **argv) {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(12);
if (argc == 2 && !strcmp("input.txt", argv[1])) {
cerr << "reading from in.txt" << endl;
freopen(argv[1], "r", stdin);
}
}
int main(int argc, char **argv) {
init(argc, argv);
int N = 2 * 1e6;
vector<vector<long long>> a(N + 1, vector<long long>(2, 0));
a[1] = {0, 0};
a[2] = {0, 0};
a[3] = {1, 1};
long long MOD = 1e9 + 7;
for (int i = 4; i <= N; i++) {
if (!a[i - 1][1] && !a[i - 2][1]) {
a[i][1] = 1;
}
a[i][0] = a[i][1] + a[i - 1][0] + 2 * a[i - 2][0];
a[i][0] %= MOD;
}
int t;
cin >> t;
while (t-- > 0) {
int n;
cin >> n;
cout << (n == 1 ? 0 : (a[n][0] * 4) % MOD) << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N_MAX = 2e6;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int dp[N_MAX];
dp[1] = dp[0] = 0;
dp[2] = 4;
for (int i = 3; i < N_MAX; i++) {
dp[i] = dp[i - 1] % MOD + (2 * dp[i - 2]) % MOD + ((i % 3 == 2) ? 4 : 0);
dp[i] %= MOD;
}
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
--n;
cout << dp[n] << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = std::pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vs = vector<string>;
template <typename T>
void output_vector(const vector<T>& v, int start = -1, int end = -1) {
if (start < 0) start = 0;
if (end < 0) end = int(v.size());
for (int i = start; i < end; i++) cout << v[i] << " ";
cout << endl;
}
int main() {
int t;
cin >> t;
vector<long long> answer(2 * 1e6 + 1, 0);
for (int j = 3; j < answer.size(); j++) {
answer[j] = (2 * answer[j - 2]) % 1000000007 + answer[j - 1];
if (j % 3 == 0) answer[j] += 4;
answer[j] %= 1000000007;
}
for (int i = 0; i < t; i++) {
long long n;
cin >> n;
cout << answer[n] << endl;
}
}
|
#include <bits/stdc++.h>
long long read() {
long long x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
using namespace std;
const long long maxn = 2e6 + 7;
const double eps = 1e-10;
const long long mod = 1e9 + 7;
struct Node {
long long data;
bool f;
};
vector<Node> node(maxn);
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
node[1].data = 0;
node[1].f = 1;
node[2].data = 0;
node[2].f = 1;
for (long long i = 3; i <= 2e6; i++) {
node[i].data = (node[i - 1].data + 2 * node[i - 2].data % mod) % mod;
if (node[i - 1].f && node[i - 2].f) {
node[i].data = (node[i].data + 4) % mod;
node[i].f = 0;
} else {
node[i].f = 1;
}
}
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
cout << node[n].data << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int mod = (long long int)1e9 + 7;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
const long long int mxn = 2e6;
vector<long long int> NC(mxn + 10, 0), OC(mxn + 10, 0), TC(mxn + 10, 0);
vector<long long int> dp(mxn + 10, 0);
NC[1] = 1;
NC[2] = 1, OC[2] = 1;
for (long long int i = 3; i <= mxn; i++) {
OC[i] = NC[i - 1];
NC[i] = NC[i - 1] + 2 * OC[i - 1] % mod;
TC[i] = OC[i - 1];
dp[i] = dp[i - 3] + 4 * TC[i];
dp[i] %= mod;
}
long long int TESTS = 1;
cin >> TESTS;
for (long long int TEST = 1; TEST <= TESTS; TEST++) {
long long int n;
cin >> n;
cout << dp[n] << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
const long long int INF = 1e18;
const long long int N = 2e6 + 20;
vector<long long int> g[N];
vector<long long int> vis(N);
vector<long long int> ans(N);
void pre() {
ans[3] = 4;
for (long long int i = 4; i < N; i++) {
ans[i] = (ans[i - 1] + 2 * ans[i - 2]) % MOD;
if (i % 3 == 0) {
ans[i] += 4;
ans[i] %= MOD;
}
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
pre();
long long int tc;
cin >> tc;
while (tc--) {
long long int n;
cin >> n;
cout << ans[n] << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
constexpr const int MOD = 1e9 + 7;
int dp[int(2e6 + 7)];
void Answer(int x) { std::cout << x << "\n"; }
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
dp[0] = dp[1] = 0;
dp[2] = 4;
for (int i = 3; i < int(2e6 + 7); i++) {
long long w = dp[i - 1];
w += 2 * dp[i - 2] + (i % 3 == 2) * 4;
w %= MOD;
dp[i] = w;
}
int testcases;
cin >> testcases;
while (testcases--) {
int n;
cin >> n;
std::cout << dp[n - 1] << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int mxn = 2e6 + 5, mod = 1e9 + 7;
long long dp[mxn], nn[mxn];
int main() {
int t;
cin >> t;
nn[1] = 1;
for (int i = 2; i < mxn; i++) nn[i] = (nn[i - 1] + 2 * nn[i - 2]) % mod;
for (int i = 3; i < mxn; i++) {
dp[i] = nn[i - 2] + dp[i - 3];
dp[i] %= mod;
}
while (t--) {
int n;
cin >> n;
cout << dp[n] * 4 % mod << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 8;
const double pi = 3.14159265359;
template <class T>
T fac(T n) {
T res = 1, i;
for (i = 2; i <= n; i++) res *= i;
return res;
}
template <class T>
T lcm(T a, T b) {
return (a * b) / __gcd(a, b);
}
template <class T>
T digitsum(T x) {
T sum = 0;
while (x) {
sum += x % 10;
x /= 10;
}
return sum;
}
void nPermute(string str, long long n) {
sort((str).begin(), (str).end());
long long i = 1;
do {
if (i == n) break;
i++;
} while (next_permutation(str.begin(), str.end()));
cout << str << endl;
}
vector<long long> factors(long long n) {
vector<long long> f;
for (long long x = 2; x * x <= n; x++) {
while (n % x == 0) {
f.push_back(x);
n /= x;
}
}
if (n > 1) f.push_back(n);
return f;
}
bool prime(long long n) {
if (n < 2) return false;
for (long long x = 2; x * x <= n; x++)
if (n % x == 0) return false;
return true;
}
long long ncr(long long n, long long k) {
long long res = 1;
if (k > n - k) k = n - k;
for (long long i = 0; i < k; i++) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
tuple<long long, long long, long long> Gcd(long long a, long long b) {
if (b == 0)
return {1, 0, a};
else {
long long x, y, g;
tie(x, y, g) = Gcd(b, a % b);
return {y, x - (a / b) * y, g};
}
}
template <class T>
T binpow(T a, T b, T m) {
a %= m;
T res = 1;
while (b > 0) {
if (b & 1) res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
const long long N = 2e6 + 5;
long long a[N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
for (long long i = 3; i < N; i++)
a[i] = (a[i - 1] + 2 * a[i - 2] + (i % 3 == 0)) % MOD;
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
cout << (4 * a[n]) % MOD << endl;
}
cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
}
|
#include <bits/stdc++.h>
using namespace std;
int64_t mod = 1e9 + 7;
int64_t spawn[2000003];
int64_t sums[2000003];
void init() {
spawn[0] = 0;
spawn[1] = 1;
sums[0] = 0;
sums[1] = 0;
sums[2] = 0;
for (int i = 0; i < 2000001; ++i) {
if (i >= 2) spawn[i] = (spawn[i - 1] + 2 * spawn[i - 2]) % mod;
if (i > 2)
sums[i] = (sums[i - 3] + spawn[i] * 4LL) % mod;
else {
sums[i] = 4LL * spawn[i];
}
}
}
void solve(int cnum) {
int n;
cin >> n;
int64_t ans = 0;
cout << (n > 2 ? sums[n - 2] : 0) << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
init();
int t;
int count = 1;
for (cin >> t; t--; solve(count), count++)
;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int64_t inf = LLONG_MAX / 2;
const int64_t mod = 1e9 + 7;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int64_t N = 2e6 + 1;
vector<int64_t> ans(N);
ans[3] = 4;
ans[4] = 4;
for (int64_t i = 3; i < N; ++i) {
if (i % 3 == 2)
ans[i] = (2 * ans[i - 2] + ans[i - 1]) % mod;
else {
int64_t A = 0;
A += 4 * ans[i - 3];
A %= mod;
if (i - 4 >= 0) A += 4 * ans[i - 4];
A %= mod;
A += ans[i - 2] + 1;
A %= mod;
ans[i] = A;
}
}
int64_t t;
cin >> t;
while (t--) {
int64_t n;
cin >> n;
cout << (4 * ans[n]) % mod << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long dp[2 * 1000 * 1000 + 7], MOD = 1000 * 1000 * 1000 + 7;
int main() {
vector<long long> ans;
long long N, i, j, n, m, a, b, s, k;
dp[3] = dp[4] = 4;
for (i = 5; i <= 2 * 1000 * 1000; i++) {
dp[i] = (dp[i - 1] + 2 * dp[i - 2] + 4 * (i % 3 == 0 ? 1 : 0)) % MOD;
}
cin >> N;
for (int z = 1; z <= N; z++) {
cin >> n;
ans.push_back(dp[n]);
}
for (i = 0; i < ans.size(); i++) cout << ans[i] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
bool iseven(long long n) {
if (n % 2 == 0)
return true;
else {
return false;
}
}
long long power(long long x, unsigned long long y) {
long long res = 1;
while (y > 0) {
if (y & 1) res = res * x;
y = y >> 1;
x = x * x;
}
return res;
}
void print(vector<char> a, int n) {
for (int i = 0; i < n; i += 1) cout << a[i];
}
bool sec(const pair<int, int> &a, const pair<int, int> &b) {
if (a.first == b.first)
return (a.second < b.second);
else {
return (a.first < b.first);
}
}
vector<long long> v(2000005, -1);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
v[0] = 0;
v[1] = 0;
v[2] = 0;
for (int i = 3; i <= 2000002; i++) {
if (v[i] == -1) {
v[i] = (v[i - 1] + (v[i - 2] * 2) % 1000000007 + (i % 3 ? 0 : 1) * 4) %
1000000007;
}
}
while (t--) {
long long n;
cin >> n;
cout << v[n] << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int P = 1000000007;
long long int f[2000001];
void fill() {
f[1] = f[2] = 0;
f[3] = 4;
for (int i = 4; i <= 2000000; i++) {
f[i] = 2 * f[i - 2] + f[i - 1];
if (i % 3 == 0) f[i] += 4;
f[i] %= P;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
int N;
fill();
while (t--) {
cin >> N;
cout << f[N] << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int dp[2000005];
const int m = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
memset(dp, 0, sizeof(dp));
dp[0] = 0;
dp[1] = 0;
dp[2] = 0;
dp[3] = 4;
long long int temp = 0;
for (long long int i = 4; i <= 2000000; i++) {
temp = 0;
if (i % 3 == 0) {
temp = 4;
}
dp[i] = ((2 * dp[i - 2]) % m + (dp[i - 1] + temp) % m) % m;
}
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
cout << dp[n] << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 2e6 + 5;
inline void solve() {}
int32_t main() {
clock_t startTime;
startTime = clock();
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout << setprecision(10);
long long t = 1;
cin >> t;
vector<long long> cnt(N, 0);
cnt[0] = 0, cnt[1] = 1;
for (long long i = 2; i <= N; i++) {
cnt[i] = 2 * cnt[i - 2] + cnt[i - 1];
cnt[i] %= mod;
}
vector<long long> res = cnt;
for (long long i = 0; i < 3; i++) {
for (long long j = i; j < N; j += 3) {
res[j + 3] += res[j];
res[j + 3] %= mod;
}
}
while (t--) {
long long n;
cin >> n;
if (n < 2) {
cout << 0 << '\n';
continue;
}
long long val = (cnt[n - 2] + (n - 5 >= 0 ? res[n - 5] : 0)) % mod;
cout << (4 * val) % mod << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int maxN = 2100000;
int dp[maxN];
int get(int n) {
if (n <= 0) {
return 0;
}
if (dp[n] != -1) {
return dp[n];
}
if (n % 3 == 2) {
return ((long long)(dp[n - 2]) * 2LL + dp[n - 1]) % MOD;
} else {
return ((long long)(dp[n - 3]) * 4LL + (long long)(dp[n - 4]) * 4LL +
(long long)(dp[n - 2]) + 4LL) %
MOD;
}
}
void precalc() {
memset(dp, -1, sizeof(dp));
dp[1] = 0;
dp[2] = 0;
dp[3] = 4;
dp[4] = 4;
for (int i = 5; i < maxN; ++i) {
dp[i] = get(i);
}
}
void solve() {
int n;
scanf("%d", &n);
printf("%d\n", dp[n]);
}
int main() {
precalc();
int t;
scanf("%d", &t);
for (int tt = 0; tt < t; ++tt) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int NUM = 2e5 + 5;
const long long int MAX = 3000000;
bool use[MAX];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int num_tests = 1;
cin >> num_tests;
vector<long long int> dp(MAX, 0);
dp[3] = 1;
use[3] = true;
for (long long int i = 4; i < MAX; i++) {
dp[i] = (2 * dp[i - 2] + dp[i - 1]) % 1000000007;
if (use[i - 1] or use[i - 2])
use[i] = 0;
else {
use[i] = 1;
dp[i] = (1 + dp[i]) % 1000000007;
}
}
while (num_tests-- > 0) {
long long int n;
cin >> n;
cout << (4 * dp[n]) % 1000000007 << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000007, inf = 1e9, N = 2e5 + 1;
const ll INF = 1e18;
ld tic, tac;
ll arr[2000002];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
arr[0] = 0;
arr[1] = 0;
arr[2] = 0;
arr[3] = 4;
arr[4] = 4;
arr[5] = 12;
for (int i = 6; i <= 2000000; i++) {
arr[i] = ((2 * arr[i - 2]) % mod + arr[i - 1]) % mod;
if (!(i % 3)) arr[i] = (arr[i] + 4) % mod;
}
while (t--) {
ll n;
cin >> n;
cout << arr[n] << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long _power(long long a, int b) {
long long ans = 1, res = a;
while (b) {
if (b & 1) ans = ans * res % mod;
res = res * res % mod;
b >>= 1;
}
return ans % mod;
}
long long s[2000005], pre[2000005];
int main() {
int t;
scanf("%d", &t);
s[1] = 0;
s[2] = 0;
s[3] = 1;
s[4] = 1;
for (int i = 5; i <= 2000000; i++) {
s[i] = (s[i - 1] + s[i - 2] * 2) % mod;
if (i % 3 == 0) {
s[i] = (s[i] + 1) % mod;
}
}
while (t--) {
int n;
scanf("%d", &n);
printf("%lld\n", (s[n] * 4) % mod);
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
long long fastpo(long long a, long long x) {
if (x == 0) return 1ll;
if (x == 1) return a;
long long y = fastpo(a, x / 2);
if (x % 2 == 0) {
return y * y;
}
return y * y * a;
}
long long inv(long long a, long long M) { return fastpo(a, M - 2); }
long long gcdExtended(long long a, long long b, long long *x, long long *y) {
if (a == 0) {
*x = 0, *y = 1;
return b;
}
long long x1, y1;
long long gcd = gcdExtended(b % a, a, &x1, &y1);
*x = y1 - (b / a) * x1;
*y = x1;
return gcd;
}
long long modInverse(long long a, long long m) {
long long x, y;
long long g = gcdExtended(a, m, &x, &y);
if (g != 1)
return -1;
else {
long long res = (x % m + m) % m;
return res;
}
}
long long gcd(long long a, long long b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long long N = 2e6 + 5;
vector<long long> dp(N, 0), ci(N, 0), ai(N, 0), bi(N, 0), ans(N, 0);
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
for (int i = 1; i < N; i++) {
if (i == 1) {
dp[i] = 1;
ci[i] = 0;
ai[i] = 0;
bi[i] = 1;
ans[i] = 0;
} else if (i == 2) {
dp[i] = 2;
ci[i] = 0;
ai[i] = 1;
bi[i] = 1;
ans[i] = 0;
} else {
ci[i - 1] = dp[i - 3];
ai[i - 1] = dp[i - 2] - dp[i - 3];
bi[i - 1] = dp[i - 1] - dp[i - 2];
dp[i] = ((ci[i - 1] + ai[i - 1] * 3 + bi[i - 1] * 2) % M + M) % M;
ans[i] = (ans[i - 3] + bi[i - 2]) % M;
}
}
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long res = ((ans[n] * 4) % M + M) % M;
cout << res << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<long long> result(2000001, 0);
vector<int> query;
int t, n, max = 0, temp;
cin >> t;
for (int i = 0; i < t; i++) {
cin >> temp;
query.push_back(temp);
if (temp > max) max = temp;
}
int p;
for (int i = 2; i <= max; i++) {
p = (i % 3 == 0) ? 1 : 0;
result[i] =
(result[i - 1] % 1000000007 + (2 * result[i - 2]) % 1000000007 + p) %
1000000007;
}
for (int i = 0; i < t; i++) {
cout << (result[query[i]] * 4) % 1000000007 << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int N = 2e6 + 10;
long long int a[N];
void solve() {
long long int n;
cin >> n;
cout << a[n] << "\n";
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
a[1] = a[2] = 0;
a[3] = 4;
for (long long int i = 4; i <= 2e6; i++) {
a[i] = (a[i - 1] + 2 * a[i - 2]) % mod;
if (i % 3 == 0) {
a[i] += 4 * 1LL;
a[i] %= mod;
}
}
long long int t;
cin >> t;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7, INF = 1e18;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t = 1, p = 0, q = 1, odd[] = {1, 0, 0}, even[] = {0, 0, 0};
vector<long long> o(2000200, 0), e(2000200, 0);
o[3] = 1;
for (int i = 4; i < 2000020; i++) {
o[i] = (2 * o[i - 2] + o[i - 1]) % mod;
if (i % 3 == 0) {
o[i] = (o[i] + 1) % mod;
}
}
cin >> t;
while (t--) {
int n;
cin >> n;
long long ans = o[n];
ans = 4 * ans;
ans = ans % mod;
cout << ans << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long dp[2000005];
int main() {
dp[0] = 0;
dp[1] = 1;
dp[2] = 1;
dp[3] = 3;
dp[4] = 5;
for (long long i = 5; i < 2000005; i++) {
dp[i] = dp[i - 1] + 2 * dp[i - 2];
dp[i] %= 1000000007;
}
for (long long i = 1; i < 2000005; i++) {
dp[i] *= 4;
if (i > 2) dp[i] += dp[i - 3];
dp[i] %= 1000000007;
}
long long test;
cin >> test;
for (long long t = 1; t <= test; t++) {
long long n;
scanf("%lld", &n);
if (n < 3)
printf("0\n");
else
printf("%lld\n", dp[n - 2]);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int k, n;
long long dp[2000005];
int main() {
int test;
cin >> test;
dp[0] = dp[1] = 0;
dp[2] = 4;
for (int i = 3; i <= 2e6; i++)
dp[i] = (2 * dp[i - 2] + dp[i - 1] + (i % 3 == 2) * 4) % mod;
while (test--) {
cin >> n;
n--;
cout << dp[n] << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long qpow(long long a, long long b, long long m) {
long long r = 1;
a %= m;
for (; b; b >>= 1) {
if (b & 1) r = r * a % m;
a = a * a % m;
}
return r;
}
const int inf = 0x7fffffff;
const int maxn = 2e6 + 10;
const long long mod = 1e9 + 7;
long long ans[maxn];
int main() {
ans[3] = 1;
for (int i = 4; i <= 2000000; i++) {
ans[i] = (ans[i - 2] * 2 + ans[i - 1]) % mod;
if (i % 3 == 0) ans[i]++;
}
ios::sync_with_stdio(false);
int T;
cin >> T;
while (T--) {
int x;
cin >> x;
cout << (ans[x] * 4) % mod << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int t, n;
long long q[2000123][2], ans[2000123];
int main() {
ios_base::sync_with_stdio(0);
q[1][0] = 1;
ans[3] = ans[4] = 4;
for (int i = 2; i < 2000123; ++i) {
q[i][0] = q[i - 1][0] + q[i - 1][1] * 2LL;
q[i][1] = q[i - 1][0];
if (i >= 5) {
ans[i] = 4LL * (q[i - 1][1]) + ans[i - 3];
}
if (ans[i] >= 1000000007LL) ans[i] %= 1000000007LL;
if (q[i][0] >= 1000000007LL) q[i][0] %= 1000000007LL;
if (q[i][1] >= 1000000007LL) q[i][1] %= 1000000007LL;
}
cin >> t;
while (t--) {
cin >> n;
cout << ans[n] << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
const int N = 2e6 + 5;
const int Mod = 1e9 + 7;
int T, n;
long long f[N];
template <typename T>
inline void read(T &a) {
a = 0;
int f = 1;
char c = getchar();
while (c > '9' || c < '0') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
a = a * 10 + c - '0';
c = getchar();
}
a *= f;
}
int main() {
f[1] = 0, f[2] = 0, f[3] = 4, f[4] = 4, f[5] = 12;
for (int i = 6; i < N; i++) {
f[i] = 2 * f[i - 2] + f[i - 1];
f[i] += (i % 3 == 0) ? 4 : 0;
f[i] %= Mod;
}
read(T);
while (T--) {
read(n);
printf("%lld\n", f[n]);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<long long> nclaws(2000001, 0);
void solve() {
int n;
cin >> n;
cout << ((nclaws[n] * 4) % 1000000007) << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
nclaws[1] = 0;
nclaws[2] = 0;
nclaws[3] = 1;
nclaws[4] = 1;
for (int i = 5; i < 2000001; i++) {
nclaws[i] = nclaws[i - 1] + 2 * nclaws[i - 2];
if (i % 3 == 0) nclaws[i]++;
nclaws[i] = nclaws[i] % 1000000007;
}
int t = 1;
cin >> t;
while (t--) solve();
}
|
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long dp[2000010], t, n;
int main() {
for (int i = 3; i <= 2000000; i++)
dp[i] = (2 * dp[i - 2] + dp[i - 1] + 4 * (i % 3 == 0)) % MOD;
cin >> t;
while (t--) {
cin >> n;
cout << dp[n] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e6 + 10, N = 1001, LOG = 25, mod = 1e9 + 7,
inf = 1e9 + 7;
long long dp[maxn], n, m;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
;
dp[1] = 0;
dp[2] = 0;
dp[3] = 4;
dp[4] = 4;
for (int i = 5; i < maxn; i++) {
dp[i] = dp[i - 1] + (2 * dp[i - 2]);
if (i % 3 == 0) dp[i] += 4;
dp[i] %= mod;
}
int t;
cin >> t;
while (t--) {
cin >> n;
cout << dp[n] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int a[2000001], b[2000001], c[2000001], d[2000001], dp[2000001];
long long int gcdExtended(long long int a, long long int b, long long int *x,
long long int *y);
long long int modInverse(long long int b, long long int m) {
long long int x, y;
long long int g = gcdExtended(b, m, &x, &y);
if (g != 1) return -1;
return (x % m + m) % m;
}
long long int modDivide(long long int a, long long int b, long long int m) {
a = a % m;
long long int inv = modInverse(b, m);
return (inv * a) % m;
}
long long int gcdExtended(long long int a, long long int b, long long int *x,
long long int *y) {
if (a == 0) {
*x = 0, *y = 1;
return b;
}
long long int x1, y1;
long long int gcd = gcdExtended(b % a, a, &x1, &y1);
*x = y1 - (b / a) * x1;
*y = x1;
return gcd;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t, i, mod = 1000000007;
cin >> t;
a[1] = 0;
b[1] = 0;
c[1] = 1;
d[1] = 0;
a[2] = 0;
b[2] = 1;
c[2] = 1;
d[2] = 0;
dp[1] = 0;
dp[2] = 0;
dp[3] = 1;
dp[4] = 1;
dp[5] = 3;
for (i = 3; i <= 2000000; i++) {
a[i] = a[i - 1] + b[i - 1];
b[i] = c[i - 1];
c[i] = c[i - 1] + c[i - 2] + c[i - 2];
d[i] = (a[i] + 1) / 2;
a[i] = a[i] % mod;
b[i] = b[i] % mod;
c[i] = c[i] % mod;
d[i] = d[i] % mod;
}
for (i = 6; i <= 2000000; i++) {
dp[i] = dp[i - 3] + d[i];
dp[i] = dp[i] % mod;
}
while (t--) {
long long int n;
cin >> n;
cout << (dp[n] * 4) % mod << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e6;
long long c0[maxn + 1];
long long c1[maxn + 1];
long long c3[maxn + 1];
long long ans[maxn + 1];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
c0[1] = 1;
c1[1] = 0;
c3[1] = 0;
for (long long i = 2; i <= maxn; i++) {
c3[i] = (c1[i - 1] + c3[i - 1]) % 1000000007;
c1[i] = (c0[i - 1]) % 1000000007;
c0[i] = (2 * c1[i - 1] + c0[i - 1]) % 1000000007;
}
ans[1] = 0;
ans[2] = 0;
ans[3] = 1;
for (long long i = 4; i <= maxn; i++) {
ans[i] = (c1[i - 1] + ans[i - 3]) % 1000000007;
}
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
if (n == 1) {
cout << 0 << endl;
continue;
}
if (n == 2) {
cout << 0 << endl;
continue;
}
cout << (ans[n] * 4) % 1000000007 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e6 + 2, MOD = 1e9 + 7;
inline long long add(long long a, long long b) {
return ((a % MOD) + (b % MOD)) % MOD;
}
inline long long mul(long long a, long long b) {
return ((a % MOD) * (b % MOD)) % MOD;
}
inline long long sub(long long a, long long b) {
return ((a % MOD) - (b % MOD) + MOD) % MOD;
}
long long lf[N], total[N], finalAns[N];
long long mod(long long a, long long b) {
a = (a > 0) ? a : (-a / b + 1) * b + a;
return a % b;
}
void solve() {
long long n;
cin >> n;
cout << finalAns[n] << "\n";
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
lf[2] = 1;
lf[1] = 1;
for (long long i = 3; i < 2e6 + 2; i++) {
lf[i] = add(lf[i - 1], lf[i - 2] * 2);
}
total[2] = 1;
total[3] = 3;
total[1] = 1;
finalAns[1] = 0;
finalAns[2] = 0;
for (long long i = 4; i < N; i++) total[i] = add(lf[i], total[i - 3]);
for (long long i = 3; i < N; i++) finalAns[i] = mul(total[i - 2], 4);
long long t;
cin >> t;
for (long long tt = 1; tt < t + 1; tt++) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int ar[2000006];
int main() {
long long int i, j, n, t;
ar[0] = 0;
ar[1] = 0;
ar[2] = 0;
ar[3] = 1;
for (i = 4; i < 2000006; i++) {
ar[i] = max((2 * ar[i - 2] + ar[i - 1]) % 1000000007,
(1 + 4 * ar[i - 3] + ar[i - 2] + 4 * ar[i - 4]) % 1000000007);
}
cin >> t;
while (t--) {
cin >> n;
cout << (ar[n] * 4) % 1000000007 << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse4")
using namespace std;
const int MOD = 1e9 + 7;
const int MX = 2e5 + 5;
const long long INF = 1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-6;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const char nl = '\n';
template <typename T>
inline T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
template <typename T>
inline T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
template <class T>
void ckmin(T& a, T b) {
a = min(a, b);
}
template <class T>
void ckmax(T& a, T b) {
a = max(a, b);
}
int pct(int x) { return __builtin_popcount(x); }
int pct(long long x) { return __builtin_popcountll(x); }
void DBG() { cerr << "]" << endl; }
template <class H, class... T>
void DBG(H h, T... t) {
cerr << h;
if (sizeof...(t)) cerr << ", ";
DBG(t...);
}
void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(), "w", stdout); }
void unsyncIO() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
void setIO(string s = "") {
unsyncIO();
if ((int)s.size()) {
setIn(s + ".in"), setOut(s + ".out");
}
}
long long pow(long long b, long long e, long long m = 0LL,
long long ans = 1LL) {
while (e) {
if (e & 1LL) {
ans *= b;
if (m) ans %= m;
}
b *= b, e >>= 1LL;
if (m) b %= m;
}
return ans;
}
int dp[2000010];
void precompute() {
dp[2] = 4;
for (int i = 3; i < 2000010; ++i) {
long long cur = dp[i - 1] + 2LL * dp[i - 2] + 4LL * (i % 3 == 2);
cur %= MOD;
dp[i] = cur;
}
}
void solve(int tcn) {
int n;
cin >> n, --n;
cout << dp[n] << nl;
}
int main() {
setIO();
precompute();
int t = 1;
cin >> t;
for (int i = 1; i <= t; ++i) {
solve(i);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
unsigned long long int expo_fast(long long int a, long long int b) {
a = a;
long long int result = 1;
while (b) {
if (b & 1) result = (result * a);
b >>= 1;
a = (a * a);
}
return (result);
}
void take_in(vector<long long int> *arr) {
for (int i = 0; i < arr->size(); i++) cin >> (*(arr))[i];
}
long long int gcd(long long int a, long long int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
unsigned long long int power(long long int x, unsigned long long int y,
long long int p) {
long long int res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
vector<long long int> dp(2000006, 0), root_used(2000006, 0);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
dp[1] = 0;
dp[2] = 0;
root_used[1] = 0;
root_used[2] = 0;
for (int i = 3; i <= 2000000; i++) {
if (root_used[i - 1] || root_used[i - 2]) {
dp[i] = ((2 * (dp[i - 2] % (1000000007))) % (1000000007) +
dp[i - 1] % (1000000007)) %
(1000000007);
root_used[i] = 0;
} else {
dp[i] = ((2 * (dp[i - 2] % (1000000007))) % (1000000007) +
(dp[i - 1] % (1000000007)) + 4) %
(1000000007);
root_used[i] = 1;
}
}
while (t--) {
long long int n;
cin >> n;
cout << dp[n] << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T, mod = 1e9 + 7;
vector<long long> a(3000000, 0), b(3000000, 0);
a[3] = 4;
b[3] = 1;
for (int i = 4; i <= 2300000; i++) {
a[i] = (a[i - 1] + 2 * a[i - 2]) % mod;
if (b[i] == 0 && b[i - 1] == 0 && b[i - 2] == 0) {
a[i] += 4;
b[i] = 1;
}
}
cin >> T;
while (T--) {
int n;
cin >> n;
cout << a[n] << '\n';
;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double epsilon = 1e-7;
signed main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t;
cin >> t;
vector<long long> dp(2e6 + 5);
dp[1] = dp[2] = 0;
for (int i = 3; i <= 2e6; i++) {
long long op1 = 4ll, op2 = 0ll;
if (i >= 5) {
op1 = (4 + (((4 * dp[i - 3] % 1000000007) % 1000000007 +
(4 * dp[i - 4] % 1000000007) % 1000000007) %
1000000007 +
dp[i - 2] % 1000000007) %
1000000007) %
1000000007;
}
op2 = (2 * (dp[i - 2] % 1000000007) % 1000000007 + dp[i - 1] % 1000000007) %
1000000007;
dp[i] = max(op1, op2);
}
while (t-- > 0) {
long long n;
cin >> n;
cout << dp[n] << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
const long long int mod = 1e9 + 7;
const int s = 2e6 + 10;
long long int dp[s];
int main() {
srand(chrono::steady_clock::now().time_since_epoch().count());
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
for (long long int i = 3; i <= s; i++) {
dp[i] = dp[i - 1];
long long int t = 2 * dp[i - 2];
if (t >= mod) t -= mod;
dp[i] = (dp[i] + t) % mod;
if (dp[i] >= mod) dp[i] -= mod;
if (i % 3 == 0) {
dp[i] = (dp[i] + 1);
if (dp[i] >= mod) dp[i] -= mod;
}
}
int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
long long int ans = dp[n] * 4 % mod;
cout << ans << "\n";
}
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.