QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#186533#4908. 完全表示hos_lyric70 192ms11704kbC++147.2kb2023-09-24 01:20:342023-09-24 01:20:34

Judging History

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

  • [2023-09-24 01:20:34]
  • 评测
  • 测评结果:70
  • 用时:192ms
  • 内存:11704kb
  • [2023-09-24 01:20:34]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")

////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
  static constexpr unsigned M = M_;
  unsigned x;
  constexpr ModInt() : x(0U) {}
  constexpr ModInt(unsigned x_) : x(x_ % M) {}
  constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
  constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
  constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
  ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
  ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
  ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
  ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
  ModInt pow(long long e) const {
    if (e < 0) return inv().pow(-e);
    ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
  }
  ModInt inv() const {
    unsigned a = M, b = x; int y = 0, z = 1;
    for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
    assert(a == 1U); return ModInt(y);
  }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
  ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
  ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
  ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
  ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
  template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
  template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
  template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
  template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
  explicit operator bool() const { return x; }
  bool operator==(const ModInt &a) const { return (x == a.x); }
  bool operator!=(const ModInt &a) const { return (x != a.x); }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////

constexpr unsigned MO = 164511353;
using Mint = ModInt<MO>;

constexpr int A = 41;
static_assert(((1LL << A) - 1) % MO == 0);
int mod(int f) {
  return f ? (1 + (f - 1) % (A - 1)) : 0;
}

/*
  F[n](x) := \sum[<T> = R^n] x^|T|
  F[0](x) = 1 + x
  
  pi: R^n = R^(n-1) * R -> R^(n-1)
  <T> = R^n ==> <pi(T)> = R^(n-1)
  F[n](x) = \sum[d|K] \mu(d) #{T | <\pi(T)> = R^(n-1) && T \cap \pi^-1(0) \subseteq d R}
          = \sum[d|K] \mu(d) d^(n-1) F[n-1]((x+1)^(K/d)-1)
  
  G[n](y) := F[n](y-1)
  G[0](y) = y
  G[n](y) = \sum[d|K] \mu(d) G[n-1](y^(K/d))
  
  K = \prod[i] P[i]^E[i]
  G[n](y) =: \sum[f] H[n][f] y^(P^f)
  H[0](z) = 1
  H[n](z) = (\prod[i] (z[i]^E[i] - P[i]^(n-1) z[i]^(E[i]-1))) H[n-1](z)
  
  ans = (x (d/dx))^M F[N](x) |[x=1]
      = \sum[k] S(M,k) x^k (d/dx)^k F[N](x) |[x=1]
      = \sum[k] S(M,k) (d/dy)^k G[N](y) |[y=2]
      = \sum[k] S(M,k) (d/dy)^k \sum[f] H[n][f] y^(P^f) |[y=2]
      = \sum[k] S(M,k) \sum[f] H[n][f] (P^f)^(fall k) 2^(P^f-k)
      = \sum[k] S(M,k) \sum[f] H[n][f] \sum[l] s(k,l) (P^f)^l 2^(P^f-k)
      = \sum[l] (\sum[k] S(M,k) s(k,l) 2^-k) \sum[f] H[n][f] (P^f)^l 2^(P^f)
*/

int N, K, M;
int T;

Mint s[1010][1010];
Mint S[1010][1010];

int I;
vector<int> P, E;

int main() {
  for (; ~scanf("%d%d%d", &N, &K, &M); ) {
    scanf("%d", &T);
    assert(T == 1);
    
    for (int m = 0; m <= M; ++m) {
      s[m][0] = 0;
      s[m][m] = 1;
      for (int k = 1; k < m; ++k) {
        s[m][k] = s[m - 1][k - 1] - (m - 1) * s[m - 1][k];
      }
    }
    for (int m = 0; m <= M; ++m) {
      S[m][0] = 0;
      S[m][m] = 1;
      for (int k = 1; k < m; ++k) {
        S[m][k] = S[m - 1][k - 1] + k * S[m - 1][k];
      }
    }
    
    P.clear();
    E.clear();
    {
      int k = K;
      for (int p = 2; p * p <= k; ++p) if (k % p == 0) {
        int e = 0;
        do {
          ++e;
          k /= p;
        } while (k % p == 0);
        P.push_back(p);
        E.push_back(e);
      }
      if (k > 1) {
        P.push_back(k);
        E.push_back(1);
      }
    }
    I = P.size();
cerr<<"N = "<<N<<", K = "<<K<<", M = "<<M<<", I = "<<I<<", P = "<<P<<", E = "<<E<<endl;
    
    Mint ans = 0;
    for (int l = 0; l <= M; ++l) {
      vector<Mint> CRT(A, 0);
      CRT[1] = 1;
      for (int i = 0; i < I; ++i) {
        const Mint ple = Mint(P[i]).pow(E[i]).pow(l);
        const Mint ple1 = Mint(P[i]).pow(E[i] - 1).pow(l);
        vector<Mint> crt(A, 0);
        crt[0] = 1;
        {
          Mint pn = 1;
          for (int n = 0; n < N; ++n) {
            vector<Mint> nxt(A, 0);
            for (int f = 0; f < A; ++f) {
              nxt[mod(f + E[i])] += crt[f] * ple;
              nxt[mod(f + E[i] - 1)] -= crt[f] * ple1 * pn;
            }
            crt = nxt;
            pn *= P[i];
          }
        }
        {
          vector<Mint> NXT(A, 0);
          int pp = 1;
          for (int f = 0; f < A; ++f) {
            for (int a = 0; a < A; ++a) {
              NXT[(a * pp) % A] += CRT[a] * crt[f];
            }
            (pp *= P[i]) %= A;
          }
          CRT = NXT;
        }
      }
      // (\sum[k] S(M,k) s(k,l) 2^-k)
      Mint coef = 0;
      {
        Mint two = Mint(2).pow(-M);
        for (int k = M; k >= l; --k) {
          coef += S[M][k] * s[k][l] * two;
          two *= 2;
        }
      }
      Mint sum = 0;
      for (int a = 0; a < A; ++a) {
        sum += CRT[a] * Mint(1LL << a);
      }
      ans += coef * sum;
    }
    printf("%u\n", ans.x);
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 4ms
memory: 11120kb

input:

2 3 665
1

output:

51745605

result:

ok "51745605"

Test #2:

score: 0
Accepted
time: 8ms
memory: 10532kb

input:

2 4 641
1

output:

54153482

result:

ok "54153482"

Test #3:

score: 0
Accepted
time: 10ms
memory: 10660kb

input:

1 6 656
1

output:

119347748

result:

ok "119347748"

Test #4:

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

input:

1 8 170
1

output:

126971959

result:

ok "126971959"

Test #5:

score: 0
Accepted
time: 5ms
memory: 11704kb

input:

1 9 816
1

output:

14287284

result:

ok "14287284"

Test #6:

score: 0
Accepted
time: 4ms
memory: 6780kb

input:

1 12 233
1

output:

37178137

result:

ok "37178137"

Test #7:

score: 0
Accepted
time: 3ms
memory: 9096kb

input:

1 16 244
1

output:

91022688

result:

ok "91022688"

Test #8:

score: 0
Accepted
time: 2ms
memory: 10440kb

input:

1 18 218
1

output:

93037058

result:

ok "93037058"

Test #9:

score: 0
Accepted
time: 7ms
memory: 11036kb

input:

1 19 645
1

output:

53944276

result:

ok "53944276"

Test #10:

score: 0
Accepted
time: 3ms
memory: 10088kb

input:

1 20 333
1

output:

81197702

result:

ok "81197702"

Test #11:

score: 0
Accepted
time: 12ms
memory: 11604kb

input:

1 2 893
1

output:

17672119

result:

ok "17672119"

Test #12:

score: 0
Accepted
time: 10ms
memory: 11268kb

input:

1 19 887
1

output:

58567516

result:

ok "58567516"

Test #13:

score: 0
Accepted
time: 6ms
memory: 11052kb

input:

2 3 504
1

output:

60763909

result:

ok "60763909"

Subtask #2:

score: 15
Accepted

Test #14:

score: 15
Accepted
time: 0ms
memory: 5852kb

input:

19 90203 0
1

output:

142145213

result:

ok "142145213"

Test #15:

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

input:

18 9697 0
1

output:

153592927

result:

ok "153592927"

Test #16:

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

input:

20 41 0
1

output:

112957727

result:

ok "112957727"

Test #17:

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

input:

20 99991 0
1

output:

151341559

result:

ok "151341559"

Subtask #3:

score: 5
Accepted

Dependency #2:

100%
Accepted

Test #18:

score: 5
Accepted
time: 1ms
memory: 5824kb

input:

999 9749 0
1

output:

77370298

result:

ok "77370298"

Test #19:

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

input:

997 55103 0
1

output:

92054017

result:

ok "92054017"

Test #20:

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

input:

1000 41 0
1

output:

6438830

result:

ok "6438830"

Test #21:

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

input:

1000 99991 0
1

output:

31676606

result:

ok "31676606"

Subtask #4:

score: 5
Accepted

Dependency #3:

100%
Accepted

Test #22:

score: 5
Accepted
time: 32ms
memory: 6112kb

input:

99996 20089 0
1

output:

163612442

result:

ok "163612442"

Test #23:

score: 0
Accepted
time: 33ms
memory: 5800kb

input:

99996 17707 0
1

output:

109099283

result:

ok "109099283"

Test #24:

score: 0
Accepted
time: 30ms
memory: 5824kb

input:

100000 41 0
1

output:

131161322

result:

ok "131161322"

Test #25:

score: 0
Accepted
time: 33ms
memory: 5824kb

input:

100000 99991 0
1

output:

84487741

result:

ok "84487741"

Subtask #5:

score: 15
Accepted

Test #26:

score: 15
Accepted
time: 0ms
memory: 5932kb

input:

998 24 0
1

output:

75129854

result:

ok "75129854"

Test #27:

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

input:

998 35 0
1

output:

120341894

result:

ok "120341894"

Test #28:

score: 0
Accepted
time: 2ms
memory: 6076kb

input:

1000 30 0
1

output:

152799538

result:

ok "152799538"

Test #29:

score: 0
Accepted
time: 2ms
memory: 5828kb

input:

1000 82 0
1

output:

117109540

result:

ok "117109540"

Test #30:

score: 0
Accepted
time: 2ms
memory: 6160kb

input:

1000 100 0
1

output:

89805014

result:

ok "89805014"

Subtask #6:

score: 5
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Test #31:

score: 5
Accepted
time: 96ms
memory: 5848kb

input:

99998 20726 0
1

output:

63876769

result:

ok "63876769"

Test #32:

score: 0
Accepted
time: 127ms
memory: 5928kb

input:

99998 10270 0
1

output:

47691333

result:

ok "47691333"

Test #33:

score: 0
Accepted
time: 190ms
memory: 5848kb

input:

100000 30030 0
1

output:

80481158

result:

ok "80481158"

Test #34:

score: 0
Accepted
time: 192ms
memory: 5932kb

input:

100000 94710 0
1

output:

61977663

result:

ok "61977663"

Test #35:

score: 0
Accepted
time: 64ms
memory: 5884kb

input:

100000 100000 0
1

output:

163629325

result:

ok "163629325"

Subtask #7:

score: 15
Accepted

Dependency #6:

100%
Accepted

Test #36:

score: 15
Accepted
time: 9ms
memory: 6308kb

input:

96 26444 100
1

output:

28274469

result:

ok "28274469"

Test #37:

score: 0
Accepted
time: 5ms
memory: 6204kb

input:

96 1381 98
1

output:

108507497

result:

ok "108507497"

Test #38:

score: 0
Accepted
time: 23ms
memory: 6248kb

input:

100 30030 100
1

output:

96954743

result:

ok "96954743"

Test #39:

score: 0
Accepted
time: 23ms
memory: 6540kb

input:

100 94710 100
1

output:

4473750

result:

ok "4473750"

Test #40:

score: 0
Accepted
time: 9ms
memory: 8204kb

input:

100 100000 100
1

output:

119621887

result:

ok "119621887"

Subtask #8:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Dependency #7:

100%
Accepted

Test #41:

score: 0
Time Limit Exceeded

input:

99996 23632 996
1

output:


result:


Subtask #9:

score: 0
Runtime Error

Test #46:

score: 0
Runtime Error

input:

99997 3 997
2
0 1 2
1 2 0
2 0 1
0 0 0
0 1 2
0 2 1

output:


result: