#include <cstdio> #define ld double #define ull unsigned long long #define ll long long #define pii pair <int, int> #define iiii pair <int, pii > #define mp make_pair #define INF 1000000000 #define MOD 1000000007 #define rep(i, x) for(int (i) = 0; (i) < (x); (i)++) inline int getint() { int x = 0, p = 1; char c = getchar(); while (c <= 32) c = getchar(); if (c == 45) p = -p, c = getchar(); while (c > 32) x = x * 10 + c - 48, c = getchar(); return x * p; } using namespace std; //ruogu_alter int n; const int mod = 998244353; // int mul(int x, int y) { return 1ll * x * y % mod; } int main() { n = getint(); ll sum0 = 0, sum1 = 0; int hh0 = 0, hh1 = 0; int res = 1, hh = 1; rep(i, n) { int x = getint() - 1; sum0 += x; sum1 += i; hh0 ^= x; hh1 ^= i; res = mul(res, x + 1); hh = mul(hh, i + 1); } sum0 -= sum1; hh0 ^= hh1; for (int i = 0; i < n; i++) if (i - (i ^ hh0) == sum0 && mul(hh, i + 1) == mul(res, (i ^ hh0) + 1)) { printf("%d\n", i + 1); return 0; } return 0; }
#include <bits/stdc++.h> #define ld double #define ull unsigned long long #define ll long long #define pii pair <int, int> #define iiii pair <int, pii > #define mp make_pair #define INF 1000000000 #define MOD 1000000007 #define rep(i, x) for(int (i) = 0; (i) < (x); (i)++) inline int getint() { int x = 0, p = 1; char c = getchar(); while (c <= 32) c = getchar(); if (c == 45) p = -p, c = getchar(); while (c > 32) x = x * 10 + c - 48, c = getchar(); return x * p; } using namespace std; //ruogu_alter const int mod = MOD; const int N = 15; const int M = 35; int n, m, f[N][N][M], a[N]; // inline void reduce(int &x) { x += x >> 31 & mod; } inline int mul(int x, int y) { return 1ll * x * y % mod; } int g0(int l, int r, int x) { if (x < 0 || l > r) return 1; if (f[l][r][x] >= 0) return f[l][r][x]; int res = 0, p = r + 1; while (p > l && (a[p - 1] >> x & 1)) --p; for (int i = p; i <= r + 1; i++) { int ansl = g0(l, i - 1, x - 1); int ansr = g0(i, r, x - 1); reduce(res += mul(ansl, ansr) - mod); } return f[l][r][x] = res; } int g1(int l, int r, int x) { if (x < 0 || l > r) return 1; if (f[l][r][x] >= 0) return f[l][r][x]; int res = 0, p = r + 1; while (p > l && !(a[p - 1] >> x & 1)) --p; for (int i = p; i <= r + 1; i++) { int ansl = g1(l, i - 1, x - 1); int ansr = g1(i, r, x - 1); reduce(res += mul(ansl, ansr) - mod); } return f[l][r][x] = res; }
int main() { n = getint(); m = getint(); int res = 1; rep(i, n) a[i] = getint(); memset(f, -1, sizeof(f)); res = mul(res, g0(0, n - 1, m - 1)); //rep(i, n) a[i] = ~a[i] & (~(-1 << m)); memset(f, -1, sizeof(f)); res = mul(res, g1(0, n - 1, m - 1)); cout << res << endl; return 0; }
#include <bits/stdc++.h> #define ld double #define ull unsigned long long #define ll long long #define pii pair <int, int> #define iiii pair <int, pii > #define mp make_pair #define INF 1000000000 #define MOD 1000000007 #define rep(i, x) for(int (i) = 0; (i) < (x); (i)++) inline int getint() { int x = 0, p = 1; char c = getchar(); while (c <= 32) c = getchar(); if (c == 45) p = -p, c = getchar(); while (c > 32) x = x * 10 + c - 48, c = getchar(); return x * p; } using namespace std; //ruogu_alter const int B = 6005; int n, mod, f[B][B << 1]; // void reduce(int &x) { x += x >> 31 & mod; } int mul(int x, int y) { return 1ll * x * y % mod; } int main() { n = getint(); mod = getint(); f[3 * n][B] = 1; for (int i = 3 * n; i > 0; i--) { rep(j, B << 1) if (f[i][j]) { reduce(f[i - 1][j + 1] += f[i][j] - mod); if (i >= 2 && j >= 1) reduce(f[i - 2][j - 1] += mul(f[i][j], i - 1) - mod); if (i >= 3) { reduce(f[i - 3][j] += mul(f[i][j], (i - 1) * (i - 2)) - mod); } } } int res = 0; for (int i = B; i < (B << 1); i++) { reduce(res += f[0][i] - mod); } cout << res << endl; return 0; }
#include <bits/stdc++.h> #define ld double #define ull unsigned long long #define ll long long #define pii pair <int, int> #define iiii pair <int, pii > #define mp make_pair #define INF 1000000000 #define MOD 1000000007 #define rep(i, x) for(int (i) = 0; (i) < (x); (i)++) inline int getint() { int x = 0, p = 1; char c = getchar(); while (c <= 32) c = getchar(); if (c == 45) p = -p, c = getchar(); while (c > 32) x = x * 10 + c - 48, c = getchar(); return x * p; } using namespace std; //ruogu_alter const int N = 1e5 + 5; int n, m, res[N]; ll suf[N]; pii a[N]; // int main() { n = getint(); m = getint(); rep(i, m) a[i] = mp(getint(), i); for (int i = m - 1; i >= 0; i--) suf[i] = suf[i + 1] + a[i].first; int now = -1, pre = -1; memset(res, -1, sizeof(res)); rep(i, m) { if (suf[i] < n - now - 1) return !printf("%d\n", -1); if (m - i > n - pre - 1) return !printf("%d\n", -1); ll x = max(1ll * n - now - 1 - suf[i + 1], 0ll); assert(x <= a[i].first); int p = max(1ll * pre + 1, 1ll * now + x - a[i].first + 1); if (!x) p = pre + 1; if (p + a[i].first - 1 >= n) return !printf("%d\n", -1); res[a[i].second] = p; pre = p; now = max(now, p + a[i].first - 1); } assert(res[m - 1] + a[m - 1].first - 1 < n); rep(i, m) printf("%d ", res[i] + 1); return 0; }
#include <bits/stdc++.h> #define ld double #define ull unsigned long long #define ll long long #define pii pair <int, int> #define iiii pair <int, pii > #define mp make_pair #define INF 1000000000 #define rep(i, x) for(int (i) = 0; (i) < (x); (i)++) inline int getint() { int x = 0, p = 1; char c = getchar(); while (c <= 32) c = getchar(); if (c == 45) p = -p, c = getchar(); while (c > 32) x = x * 10 + c - 48, c = getchar(); return x * p; } using namespace std; const int mod = 1e9 + 7; inline void reduce(int &x) { x += x >> 31 & mod; } inline int mul(int x, int y) { return 1ll * x * y % mod; } //ruogu_alter const int N = 305; int n, m; bitset<N> b, a[N], c[N]; // bool ins(bitset<N> &f) { for (int i = n - 1; i >= 0; i--) { if (!f[i]) continue; if (c[i].none()) return c[i] = f, true; f ^= c[i]; } return false; } void solve() { n = getint(); m = getint(); rep(i, n) c[i].reset(), a[i].reset(); b.reset(); for (int i = 0; i < m; i++) { int x = getint() - 1, y = getint() - 1, z = getint(); a[x][y] = a[y][x] = 1; a[x][x].flip(); a[y][y].flip(); b[x] = b[x] ^ z; b[y] = b[y] ^ z; } rep(i, n) ins(a[i]); printf("%s\n", ins(b) ? "no" : "yes"); } int main() { int t = getint(); rep(i, t) solve(); return 0; }
var t, n, i, ii, res, c: longint; begin read(t); for ii := 1 to t do begin read(n); c := 1; res := 0; while n > 0 do begin if n mod 2 = 1 then begin res := res + c - 1; end; c := c * 2; n := n div 2; end; writeln(res); end; end.
#include <bits/stdc++.h> #define ld double #define ull unsigned long long #define ll long long #define pii pair <int, int> #define iiii pair <int, pii > #define mp make_pair #define INF 1000000000 #define rep(i, x) for(int (i) = 0; (i) < (x); (i)++) inline int getint() { int x = 0, p = 1; char c = getchar(); while (c <= 32) c = getchar(); if (c == 45) p = -p, c = getchar(); while (c > 32) x = x * 10 + c - 48, c = getchar(); return x * p; } using namespace std; const int mod = 1e9 + 7; inline void reduce(int &x) { x += x >> 31 & mod; } inline int mul(int x, int y) { return 1ll * x * y % mod; } //ruogu_alter const int N = 5e5 + 5; int n, res[N]; bool fg[N]; // int main() { n = getint(); int p = n, c = n; for (int i = 2; i <= n; i++) res[i] = 1; for (int i = n; i >= 1; i--) { for (int j = i + i; j <= n; j += i) { if (!fg[j]) { fg[j] = true; --c; } } while (p > c) res[p--] = i; } for (int i = 2; i <= n; i++) printf("%d ", res[i]); return 0; }
#include <bits/stdc++.h> #define ld double #define ull unsigned long long #define ll long long #define pii pair <int, int> #define iiii pair <int, pii > #define mp make_pair #define INF 1000000000 #define rep(i, x) for(int (i) = 0; (i) < (x); (i)++) inline int getint() { int x = 0, p = 1; char c = getchar(); while (c <= 32) c = getchar(); if (c == 45) p = -p, c = getchar(); while (c > 32) x = x * 10 + c - 48, c = getchar(); return x * p; } using namespace std; const int mod = 1e9 + 7; inline void reduce(int &x) { x += x >> 31 & mod; } inline int mul(int x, int y) { return 1ll * x * y % mod; } //ruogu_alter const int N = 505; int n, a[N][N]; // int main() { n = getint(); if (n <= 2) return !printf("%d\n", -1); int p = n * n; a[1][2] = p--; a[1][1] = p--; a[2][0] = p--; a[0][1] = p--; a[0][2] = p--; a[2][2] = p--; a[2][1] = p--; a[1][0] = p--; a[0][0] = p--; for (int i = 3; i < n; i++) { if (i & 1) { int x = 0, y = i; while (x <= i) a[x++][y] = p--; x = i, y = i - 1; while (y >= 0) a[x][y--] = p--; } else { int x = i, y = 0; while (y <= i) a[x][y++] = p--; x = i - 1, y = i; while (x >= 0) a[x--][y] = p--; } } rep(i, n) { rep(j, n) printf("%d ", a[i][j]); printf("\n"); } return 0; }