-
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
12 changed files
with
398 additions
and
12 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 |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
"-D_FORTIFY_SOURCE=2", | ||
"-ggdb3", | ||
"-Wextra", | ||
//"-ftrapv" | ||
"-ftrapv" | ||
] | ||
}, | ||
"windows": { | ||
|
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
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
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
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
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
File renamed without changes.
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,124 @@ | ||
#include <cstdio> | ||
#include <cstring> | ||
#include <limits> | ||
namespace IO { | ||
char in[1 << 21]; | ||
void init() { | ||
fread(in, 1, sizeof(in), stdin); | ||
} | ||
int getc() { | ||
static char* S = in; | ||
return *S++; | ||
} | ||
} | ||
int read() { | ||
int res = 0, c; | ||
do | ||
c = IO::getc(); | ||
while(c < '0' || c > '9'); | ||
while('0' <= c && c <= '9') { | ||
res = res * 10 + c - '0'; | ||
c = IO::getc(); | ||
} | ||
return res; | ||
} | ||
const int size = 1 << 21, mod = 998244353; | ||
typedef long long Int64; | ||
#define asInt64 static_cast<Int64> | ||
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* A, int end) { | ||
for(int i = 1; i <= end; i <<= 1) { | ||
int m = i >> 1; | ||
for(int j = 0; j < end; j += i) | ||
for(int k = 0; k < m; ++k) { | ||
int &x = A[j + k + m], &y = A[j + k]; | ||
x = add(x, y); | ||
} | ||
} | ||
} | ||
void IFWT(int* A, int end) { | ||
for(int i = 1; i <= end; i <<= 1) { | ||
int m = i >> 1; | ||
for(int j = 0; j < end; j += i) | ||
for(int k = 0; k < m; ++k) { | ||
int &x = A[j + k + m], &y = A[j + k]; | ||
x = sub(x, y); | ||
} | ||
} | ||
} | ||
typedef int(Arr)[22][size]; | ||
Arr A, B; | ||
int bcnt[size], D[size]; | ||
void clear(Arr& S, int n) { | ||
int end = 1 << n; | ||
for(int k = 0; k <= n; ++k) | ||
memset(S[k], 0, sizeof(int) * end); | ||
} | ||
const Int64 lim = std::numeric_limits<Int64>::max() - | ||
asInt64(mod - 1) * (mod - 1); | ||
Int64 C[size]; | ||
void conv(int* b, int n) { | ||
int end = 1 << n; | ||
clear(B, n); | ||
for(int i = 0; i < end; ++i) | ||
B[bcnt[i]][i] = b[i]; | ||
for(int i = 0; i <= n; ++i) | ||
FWT(B[i], end); | ||
for(int i = 0; i <= n; ++i) { | ||
memset(C, 0, sizeof(Int64) * end); | ||
for(int j = 0; j <= i; ++j) { | ||
int *X = A[j], *Y = B[i - j]; | ||
for(int k = 0; k < end; ++k) { | ||
C[k] += asInt64(X[k]) * Y[k]; | ||
if(C[k] > lim) | ||
C[k] %= mod; | ||
} | ||
} | ||
for(int k = 0; k < end; ++k) | ||
D[k] = C[k] % mod; | ||
IFWT(D, end); | ||
for(int j = 0; j < end; ++j) | ||
if(bcnt[j] == i) | ||
b[j] = D[j]; | ||
} | ||
} | ||
int base[size], powv[size]; | ||
int main() { | ||
IO::init(); | ||
int n = read(); | ||
int m = read(); | ||
int k = read(); | ||
int end = 1 << n; | ||
for(int i = 0; i < end; ++i) | ||
bcnt[i] = bcnt[i >> 1] + (i & 1); | ||
for(int i = 1; i <= m; ++i) | ||
++base[read()]; | ||
Int64 res = base[end - 1]; | ||
|
||
memcpy(powv, base, sizeof(int) * end); | ||
|
||
for(int i = 0; i < end; ++i) | ||
A[bcnt[i]][i] = base[i]; | ||
for(int i = 0; i <= n; ++i) | ||
FWT(A[i], end); | ||
|
||
Int64 inv[50]; | ||
inv[0] = inv[1] = 1; | ||
for(int i = 2; i <= k; ++i) | ||
inv[i] = (mod - mod / i) * inv[mod % i] % mod; | ||
for(int i = 1; i <= k; ++i) | ||
inv[i] = inv[i - 1] * inv[i] % mod; | ||
for(int i = 2; i <= k; ++i) { | ||
conv(powv, n); | ||
res = (res + powv[end - 1] * inv[i]) % mod; | ||
} | ||
printf("%lld\n", res); | ||
return 0; | ||
} |
File renamed without changes.
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,61 @@ | ||
#include <cstdio> | ||
const int size = 10000005, mod = 1000000007; | ||
typedef long long Int64; | ||
#define asInt64 static_cast<Int64> | ||
int f[size], g[size], p[size], ffac[size], gfac[size], | ||
d[size], pk[size]; | ||
bool flag[size]; | ||
void pre(int n) { | ||
f[1] = g[1] = 1; | ||
int pcnt = 0; | ||
for(int i = 2; i <= n; ++i) { | ||
if(!flag[i]) { | ||
p[++pcnt] = i; | ||
f[i] = ffac[i] = 2; | ||
|
||
pk[i] = asInt64(i) * i % mod; | ||
g[i] = gfac[i] = (1 + pk[i]) % mod; | ||
d[i] = 1; | ||
} | ||
for(int j = 1; j <= pcnt && i * p[j] <= n; | ||
++j) { | ||
int val = i * p[j]; | ||
flag[val] = true; | ||
if(i % p[j]) { | ||
ffac[val] = ffac[p[j]]; | ||
f[val] = f[i] * ffac[val]; | ||
|
||
d[val] = i; | ||
pk[val] = pk[p[j]]; | ||
gfac[val] = gfac[p[j]]; | ||
g[val] = | ||
asInt64(g[i]) * gfac[val] % mod; | ||
} else { | ||
ffac[val] = ffac[i] + 1; | ||
f[val] = f[i] / ffac[i] * ffac[val]; | ||
|
||
d[val] = d[i]; | ||
pk[val] = | ||
asInt64(pk[i]) * pk[p[j]] % mod; | ||
gfac[val] = (gfac[i] + pk[val]) % mod; | ||
g[val] = asInt64(g[d[val]]) * | ||
gfac[val] % mod; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
int main() { | ||
int q, x, a, b, c; | ||
scanf("%d%d%d%d%d", &q, &x, &a, &b, &c); | ||
pre(c); | ||
Int64 A = 0, B = 0; | ||
for(int k = 1; k <= q; ++k) { | ||
if(x & 1) | ||
++A, B += 4; | ||
A += f[x], B += g[x]; | ||
x = (asInt64(x) * a + b) % c + 1; | ||
} | ||
printf("%lld\n%lld\n", A % mod, B % mod); | ||
return 0; | ||
} |
Oops, something went wrong.