QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#108865 | #6328. Many Products | 8BQube | WA | 3ms | 3508kb | C++14 | 3.5kb | 2023-05-26 20:02:16 | 2023-05-26 20:02:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define SZ(a) ((int)a.size())
const int MOD = 998244353;
const int L = 40;
void add(int &x, int val) {
x += val;
if (x >= MOD) x -= MOD;
}
int arr[200005];
int dp[2][L][L];
int C[5 * L][5 * L];
int H(int n, int m) {
if (n + m - 1 < m) return 0;
return C[n + m - 1][m];
}
int cal(const vector<int> &buk, int k) {
if (buk.empty()) return k == 0;
if (k == 0) return buk.empty();
int sum = 0;
for (int j : buk)
sum += j;
if (k > sum) return 0;
int res = 0;
for (int i = 0; i < k; ++i) {
int cur = 1;
for (int j : buk)
cur = (ll)cur * H(k - i, j) % MOD;
cur = (ll)cur * C[k][i] % MOD;
if (i & 1) add(res, MOD - cur);
else add(res, cur);
}
return res;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n;
ll m;
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> arr[i];
C[0][0] = 1;
for (int i = 1; i < 5 * L; ++i) {
C[i][0] = 1;
for (int j = 1; j <= i; ++j) {
C[i][j] = C[i - 1][j];
add(C[i][j], C[i - 1][j - 1]);
}
}
vector<ll> p;
{
ll x = m;
for (ll i = 2; i * i <= x; ++i)
if (x % i == 0) {
p.pb(i);
while (x % i == 0) x /= i;
}
if (x > 1) p.pb(x);
}
vector<ll> fac;
for (ll i = 1; i * i <= m; ++i)
if (m % i == 0) {
fac.pb(i);
if (i * i != m) fac.pb(m / i);
}
dp[0][0][0] = 1;
int prv = 0, nxt = 1;
for (int i = 1; i <= n; ++i) {
memset(dp[nxt], 0, sizeof(dp[nxt]));
for (int j = 0; j < L; ++j)
for (int k = 0; k < L; ++k)
if (dp[prv][j][k]) {
add(dp[nxt][j + 1][k], dp[prv][j][k]);
add(dp[nxt][j][k + 1], (ll)dp[prv][j][k] * arr[i] % MOD);
add(dp[nxt][j][k], (ll)dp[prv][j][k] * (arr[i] + 1) % MOD);
}
swap(prv, nxt);
}
int ans = 0;
for (ll x : fac) {
vector<int> buk, ibuk;
for (ll j : p) {
ll cur = x;
if (cur % j == 0) {
buk.pb(0);
while (cur % j == 0) cur /= j, ++buk.back();
}
cur = m / x;
if (cur % j == 0) {
ibuk.pb(0);
while (cur % j == 0) cur /= j, ++ibuk.back();
}
}
vector<int> mth, imth;
for (int j = 0; j < L; ++j) {
mth.pb(cal(buk, j));
imth.pb(cal(ibuk, j));
}
int cur = 0;
for (int j = 0; j < L; ++j)
for (int k = 0; k < L; ++k) {
add(cur, (ll)dp[prv][j][k] % MOD * mth[j] % MOD * imth[k] % MOD);
}
add(ans, (ll)cur * (x % MOD) % MOD);
//cerr << x << ": " << cur << "\n";
}
vector<int> buk;
for (ll j : p) {
ll cur = m;
if (cur % j == 0) {
buk.pb(0);
while (cur % j == 0) cur /= j, ++buk.back();
}
}
int mul = 1;
for (int i = 1; i <= n; ++i)
mul = (ll)mul * arr[i] % MOD;
for (int k = 1; k < L; ++k)
add(ans, (ll)cal(buk, k) * mul % MOD);
for (int j : buk)
mul = (ll)mul * (j + 1) % MOD;
mul -= 1;
add(ans, MOD - mul);
cout << ans << "\n";
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 3508kb
input:
2 3 0 1
output:
11
result:
wrong answer 1st numbers differ - expected: '10', found: '11'