QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#745738#9619. 乘积,欧拉函数,求和test_algthWA 0ms3580kbC++202.2kb2024-11-14 11:18:342024-11-14 11:18:34

Judging History

你现在查看的是最新测评结果

  • [2024-11-14 11:18:34]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3580kb
  • [2024-11-14 11:18:34]
  • 提交

answer

#include <bits/stdc++.h>

const int MAXW = 3003;
const int MAXN = 2024;
const int P = 998244353;

inline int add(int a, int b) {
  return a -= (a += b) >= P ? P : 0;
}

inline void incr(int& a, int b) {
  a = add(a, b);
}

inline int qPow(int a, int b) {
  int res = 1;
  for (;b ; b >>= 1, a = 1ll * a * a % P) {
    if (b & 1) {
      res = 1ll * res * a % P;
    }
  }
  return res;
}

const int MAXS = 1 << 16;
int  A[MAXN], mask[MAXN];
std::vector <int> primes, values[MAXW];
std::bitset <MAXW> notPrime;
int N;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);

  for (int i = 2; i * i < MAXW - 2; ++i) {
    if (notPrime[i]) {
      primes.push_back(i);
    }

    for (int j = i + i; j < MAXW - 2; j += i)
      notPrime[j] = true;
  }

  std::cin >> N;
  for (int i = 1; i <= N; ++i) {
    std::cin >> A[i];

    int x = A[i], t = 0;
    for (int p : primes) {
      while (x % p == 0) {
        mask[i] |= 1 << t;
        x /= p;
      }
      ++t;
    }

    values[x].push_back(i);
  }

  int all = primes.size();
  std::vector <std::array <int, 2>> dp(1 << all, {0, 0});
  dp[0][0] = 1;

  std::vector <int> prod(1 << all, 0);
  prod[0] = 1;
  for (int s = 1; s < (1 << all); ++s) {
    int x = s & -s, p = __builtin_ctz(x);
    prod[s] = 1ll * prod[s ^ x] * (primes[p] - 1) % P * qPow(primes[p], P - 2) % P;
  }

  for (int i = 1; i < MAXW; ++i) {
    if (!values[i].size()) continue;
    int newP = i == 1 ? 1 : (1ll * (i - 1) * qPow(i, P - 2) % P);
    
    for (int p : values[i]) {
      std::vector <std::array <int, 2>> ndp(1 << all, {0, 0});
      for (int s = 0; s < (1 << all); ++s) {
        int ad = (s ^ mask[p]) & mask[p];
        incr(ndp[s | ad][1], 1ll * add(1ll * dp[s][0] * newP % P, dp[s][1]) * prod[ad] % P * A[p] % P);
        incr(ndp[s][1], dp[s][1]);
        incr(ndp[s][0], dp[s][0]);
      }
      dp = ndp;
    }

    for (int s = 0; s < (1 << all); ++s) {
      incr(dp[s][0], dp[s][1]);
      dp[s][1] = 0;
    }
  }

  int ans = 0;
  for (int s = 0; s < (1 << all); ++s) {
    incr(ans, dp[s][0]);
  }

  std::cout << ans << '\n';
  return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3580kb

input:

5
1 6 8 6 2

output:

902

result:

wrong answer 1st lines differ - expected: '892', found: '902'