-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include <cstdio> | ||
typedef long long Int64; | ||
#define asInt64 static_cast<Int64> | ||
const int mod = 998244353, size = 1 << 20; | ||
const Int64 inv2 = (mod + 1) / 2; | ||
Int64 powm(Int64 a, Int64 k) { | ||
Int64 res = 1; | ||
while (k) { | ||
if (k & 1) | ||
res = res * a % mod; | ||
k >>= 1, a = a * a % mod; | ||
} | ||
return res; | ||
} | ||
int add(int a, int b) { | ||
a += b; | ||
return a < mod ? a : a - mod; | ||
} | ||
int sub(int a, int b) { | ||
a -= b; | ||
return a >= 0 ? a : a + mod; | ||
} | ||
void FWT(int n, int *A) { | ||
for (int i = 2; i <= n; i <<= 1) { | ||
int m = i >> 1; | ||
for (int j = 0; j < n; j += i) | ||
for (int k = 0; k < m; ++k) { | ||
int &x = A[j + k], &y = A[j + m + k], t = y; | ||
y = sub(x, t); | ||
x = add(x, t); | ||
} | ||
} | ||
} | ||
void IFWT(int n, int *A) { | ||
for (int i = 2; i <= n; i <<= 1) { | ||
int m = i >> 1; | ||
for (int j = 0; j < n; j += i) | ||
for (int k = 0; k < m; ++k) { | ||
int &x = A[j + k], &y = A[j + m + k], t = y; | ||
y = sub(x, t) * inv2 % mod; | ||
x = add(x, t) * inv2 % mod; | ||
} | ||
} | ||
} | ||
int A[size], B[size]; | ||
int sg(int x) { | ||
return x - (1 << (31 - __builtin_clz(x))); | ||
} | ||
int main() { | ||
Int64 k; | ||
int m; | ||
scanf("%lld%d", &k, &m); | ||
int sum = powm(m, k); | ||
for (int i = 1; i <= m; ++i) { | ||
int val = sg(i); | ||
++A[val]; | ||
} | ||
int p = 1 << (31 - __builtin_clz(m)); | ||
FWT(p, A); | ||
B[0] = 1; | ||
FWT(p, B); | ||
while (k) { | ||
if (k & 1) { | ||
for (int i = 0; i < p; ++i) | ||
B[i] = asInt64(B[i]) * A[i] % mod; | ||
} | ||
k >>= 1; | ||
if (k) { | ||
for (int i = 0; i < p; ++i) | ||
A[i] = asInt64(A[i]) * A[i] % mod; | ||
} | ||
} | ||
IFWT(p, B); | ||
printf("%d\n", sub(sum, B[0])); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <cstdio> | ||
int sg[2005]; | ||
void calcSG(int x) { | ||
bool use[2005] = {}; | ||
for (int y = 1; y < x; ++y) | ||
if ((x ^ y) < x && (x ^ y) >= 1) | ||
use[sg[x ^ y]] = true; | ||
for (int z = 0;; ++z) | ||
if (!use[z]) { | ||
sg[x] = z; | ||
return; | ||
} | ||
} | ||
int sgo1(int x) { | ||
return x - (1 << (31 - __builtin_clz(x))); | ||
} | ||
int main() { | ||
for (int i = 1; i <= 2000; ++i) { | ||
calcSG(i); | ||
printf("%d %d %d\n", i, sg[i], sgo1(i)); | ||
if (sg[i] != sgo1(i)) | ||
throw; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <cstdio> | ||
int sg(int x) { | ||
return x - (1 << (31 - __builtin_clz(x))); | ||
} | ||
int cnt = 0; | ||
void DFS(int v, int m, int xorv) { | ||
if (v) { | ||
for (int i = 1; i <= m; ++i) | ||
DFS(v - 1, m, xorv ^ sg(i)); | ||
} else | ||
cnt += (xorv != 0); | ||
} | ||
int main() { | ||
int v, m; | ||
scanf("%d%d", &v, &m); | ||
DFS(v, m, 0); | ||
printf("%d\n", cnt); | ||
return 0; | ||
} |