QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#797126#9619. 乘积,欧拉函数,求和asxziillWA 22ms3712kbC++233.1kb2024-12-02 17:07:192024-12-02 17:07:26

Judging History

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

  • [2024-12-02 17:07:26]
  • 评测
  • 测评结果:WA
  • 用时:22ms
  • 内存:3712kb
  • [2024-12-02 17:07:19]
  • 提交

answer

#include <bits/stdc++.h>

using ll = long long;

constexpr int P = 998244353;

ll mul(ll a, ll b) {
  return a * b % P;
}

ll add(ll a, ll b) {
  ll res = a + b;
  return (res >= P ? res - P : res);
}

ll neg(ll x) {
  return (x == 0 ? x : P - x);
}

ll sub(ll a, ll b) {
  return add(a, neg(b));
}


const int N = 10;
const int V = 3000;
const int S = 20;
const int v = 30;
int pw[v][S + 1];

std::vector<int> minp, primes;
std::vector<int> inv(v + 1), pi;
void sieve(int n) {
  minp.assign(n + 1, 0);
  primes.clear();

  for (int i = 2; i <= n; i++) {
    if (minp[i] == 0) {
      minp[i] = i;
      primes.push_back(i);
    }

    for (int p : primes) {
      if (i * p > n) {
        break;
      }
      minp[i * p] = p;
      if (p == minp[i]) {
        break;
      }
    }
  }

  for (int x : primes) {
    if (x < v) {
      inv[x] = pi.size();
      pi.push_back(x);

      pw[x][0] = 1;
      for (int i = 0; i < S; i++) {
        pw[x][i + 1] = mul(pw[x][i], x);
      }
    } else {
      break;
    }
  }
}


void solve() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  std::map<int, std::vector<int>> map;

  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
    int mx = 0;
    int x = a[i];
    while (x > 1) {
      mx = std::max(mx, minp[x]);
      x /= minp[x];
    }
    if (mx < v) {
      map[-1].push_back(a[i]);
    } else {
      map[mx].push_back(a[i] / mx);
    }
  }

  int s = (1 << (N + 1));
  int si = (1 << (N));
  std::vector<int> f(s);
  f[0] = 1;
  for (auto &[p, arr] : map) {
    for (int x : arr) {
      // std::cout << p << " " << x << " p x \n";
      auto g = f;
      std::vector<int> cnt(pi.size());
      while (x > 1) {
        cnt[inv[minp[x]]]++;
        x /= minp[x];
      }

      for (int sta = 0; sta < si; sta++) {
        int t = sta;
        int tmp = 1;
        for (int i = 0; i < pi.size(); i++) {
          if (cnt[i] > 0) {
            t |= (1 << i);

            if ((sta >> i) & 1) {
              tmp = mul(tmp, pw[pi[i]][cnt[i]]);
            } else {
              tmp = mul(tmp, sub(pw[pi[i]][cnt[i]], pw[pi[i]][cnt[i] - 1]));
            }
          }
        }

        if (p == -1) {
          g[t] = add(g[t], mul(tmp, f[sta]));
        } else {
          t |= (1 << N);
          g[t] = add(g[t], mul(tmp, mul(f[sta], p - 1)));
          g[t] = add(g[t], mul(tmp, mul(f[sta | (1 << N)], p)));
        }
      }

      f = std::move(g);
    }

    for (int sta = 0; sta < si; sta++) {
      f[sta] = add(f[sta], f[sta | (1 << N)]);
      f[sta | (1 << N)] = 0;
    }
  }

  int ans = 0;
  for (int sta = 0; sta < si; sta++) {
    ans = add(ans, f[sta]);
  }
  std::cout << ans;
}

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

  sieve(V);
  // std::cout << primes[9] << "\n";

  // sieve(v);
  // std::cout << v;
  // for (int i = 0; i < 5; i++) {
  //   std::cout << i << " " << pi[i] << " " << inv[pi[i]] << "\n";
  // }

  solve();
  // std::cout << sub(pw[11][1], pw[11][0]);

  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3712kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: -100
Wrong Answer
time: 22ms
memory: 3672kb

input:

2000
79 1 1 1 1 1 1 2803 1 1 1 1 1 1 1609 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2137 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 613 1 499 1 211 1 2927 1 1 1327 1 1 1123 1 907 1 2543 1 1 1 311 2683 1 1 1 1 2963 1 1 1 641 761 1 1 1 1 1 1 1 1 1 1 1 1489 2857 1 1 1 1 1 1 1 1 1 1 1 1 1 967 1 821 1 1 1 1 2143 1861...

output:

331288822

result:

wrong answer 1st lines differ - expected: '50965652', found: '331288822'