QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#578173#9309. GraphDBsoleilWA 1ms3828kbC++202.7kb2024-09-20 17:09:582024-09-20 17:09:59

Judging History

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

  • [2024-09-20 17:09:59]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3828kb
  • [2024-09-20 17:09:58]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
static constexpr int mod = 998244353;
int64_t add(int64_t x, int64_t y) { return (x + y) % mod; }
int64_t sub(int64_t x, int64_t y) { return (x - y + mod) % mod; }
int64_t mul(int64_t x, int64_t y) { return x % mod * (y % mod) % mod; }
int64_t qpow(int64_t x, int64_t y) {
  int64_t r = 1; x %= mod;
  for (; y; y >>= 1) if (y & 1) r = mul(r, x);
  return r;
} // qpow
namespace min25 {
  vector<bool> np; vector<int> mu;
  vector<uint32_t> primes; vector<uint64_t> v;
  uint64_t n; uint32_t sqrtn; int pn;
  void sieve(int N) {
    np.resize(N + 1); mu.resize(N + 1); mu[1] = 1;
    for (int i = 2; i <= N; i++) {
      if (!np[i]) primes.push_back(i), mu[i] = -1;
      for (int p: primes) {
        if (i * p > N) break;
        mu[i * p] = -mu[i]; np[i * p] = true;
        if (i % p == 0) { mu[i * p] = 0; break; }
      }
    }
  }
  void init(uint64_t _n) {
    n = _n; sqrtn = sqrt(_n);
    while ((uint64_t)(sqrtn + 1) * (sqrtn + 1) <= _n) sqrtn++;
    sieve(sqrtn); pn = primes.size();
    v.reserve(sqrtn * 2 + 10);
    for (uint64_t l = 1, r; l <= n; l = r + 1)
      r = n / (n / l), v.push_back(n / l);
  }
  int ind(uint64_t x) { return x <= sqrtn ? v.size() - x : n / x - 1; }
  uint64_t fastdiv(uint64_t x, uint64_t _m) { return (uint64_t)((__uint128_t) x * _m >> 64); }
  // fp[i] = \sum_{2 <= k <= v[i], k is prime} f(k)
  // sf(x) = \sum_{2 <= i <= x} f(i)
  // f(x * y) = f(x) * f(y)
  template<typename F, typename G>
  pair<vector<int64_t>, vector<int64_t>> calcfp(F f, G sf) {
    vector<int64_t> pf(pn + 1), fp(v.size());
    for (int i = 0; i < pn; i++)
      pf[i + 1] = pf[i] + f(primes[i]);
    for (int i = 0; i < (int) v.size(); i++) fp[i] = sf(v[i]);
    for (int j = 0; j < pn; j++) {
      auto pj = primes[j];
      auto _pj = ~0ull / pj + 1;
      uint64_t z = (uint64_t)pj * pj;
      int64_t vv = f(pj);
      for (int i = 0; z <= v[i]; i++) {
        int k = ind(fastdiv(v[i], _pj));
        fp[i] -= vv * (fp[k] - pf[j]);
      }
    }
    return make_pair(move(fp), move(pf));
  }
} // min25
int main(void) {
  ios_base::sync_with_stdio(false);
  int64_t n;
  cin >> n;
  min25::init(n);
  auto f = [](int64_t x) { return 1; };
  auto sf = [](int64_t x) { return x - 1; };
  auto [fp, pf] = min25::calcfp(f, sf);
  auto F = [&](int64_t n)->int64_t {
    if (n <= 2) return 1;
    if (n == 3) return 3;
    int t = fp[min25::ind(n)] - fp[min25::ind(n / 2)];
    return mul(qpow(n % mod, t), sub(n % mod, add(t, 1)));
  };
  int64_t ans = 1;
  for (int64_t l = 1, r; l <= n; l = r + 1) {
    r = n / (n / l);
    ans = mul(ans, qpow(F(n / l), r - l + 1));
  }
  printf("%lld\n", ans);
  return 0;
} // main

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3768kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3816kb

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3828kb

input:

123

output:

733421489

result:

wrong answer expected '671840470', found '733421489'