結果

問題 No.732 3PrimeCounting
ユーザー onakasuitacityonakasuitacity
提出日時 2020-10-17 14:51:03
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,794 bytes
コンパイル時間 309 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 271,580 KB
最終ジャッジ日時 2023-09-28 08:01:52
合計ジャッジ時間 20,733 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
71,424 KB
testcase_01 AC 64 ms
71,228 KB
testcase_02 AC 64 ms
71,184 KB
testcase_03 AC 62 ms
71,292 KB
testcase_04 AC 63 ms
71,540 KB
testcase_05 AC 67 ms
71,000 KB
testcase_06 AC 82 ms
76,712 KB
testcase_07 AC 70 ms
76,100 KB
testcase_08 AC 71 ms
76,072 KB
testcase_09 AC 71 ms
76,420 KB
testcase_10 AC 70 ms
76,420 KB
testcase_11 AC 71 ms
76,224 KB
testcase_12 AC 70 ms
76,284 KB
testcase_13 AC 69 ms
76,396 KB
testcase_14 AC 69 ms
75,900 KB
testcase_15 AC 69 ms
76,096 KB
testcase_16 AC 69 ms
76,216 KB
testcase_17 AC 72 ms
76,128 KB
testcase_18 AC 70 ms
76,008 KB
testcase_19 AC 69 ms
76,304 KB
testcase_20 AC 81 ms
76,604 KB
testcase_21 AC 87 ms
77,432 KB
testcase_22 AC 88 ms
77,624 KB
testcase_23 AC 73 ms
76,308 KB
testcase_24 AC 76 ms
76,472 KB
testcase_25 AC 99 ms
79,056 KB
testcase_26 AC 101 ms
78,588 KB
testcase_27 AC 81 ms
77,284 KB
testcase_28 AC 84 ms
77,060 KB
testcase_29 AC 87 ms
77,520 KB
testcase_30 AC 87 ms
77,520 KB
testcase_31 AC 89 ms
77,592 KB
testcase_32 AC 97 ms
78,664 KB
testcase_33 AC 96 ms
78,712 KB
testcase_34 AC 98 ms
78,668 KB
testcase_35 AC 99 ms
78,728 KB
testcase_36 AC 97 ms
78,748 KB
testcase_37 AC 75 ms
76,568 KB
testcase_38 AC 75 ms
76,576 KB
testcase_39 AC 99 ms
78,636 KB
testcase_40 AC 91 ms
77,584 KB
testcase_41 AC 88 ms
77,608 KB
testcase_42 AC 88 ms
77,472 KB
testcase_43 AC 88 ms
77,464 KB
testcase_44 AC 89 ms
77,452 KB
testcase_45 AC 89 ms
77,132 KB
testcase_46 AC 84 ms
77,368 KB
testcase_47 AC 87 ms
77,468 KB
testcase_48 AC 103 ms
79,228 KB
testcase_49 AC 104 ms
79,180 KB
testcase_50 AC 90 ms
77,468 KB
testcase_51 AC 88 ms
77,416 KB
testcase_52 AC 82 ms
77,600 KB
testcase_53 AC 139 ms
99,556 KB
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 AC 194 ms
108,684 KB
testcase_58 AC 185 ms
108,472 KB
testcase_59 AC 137 ms
99,576 KB
testcase_60 AC 255 ms
137,968 KB
testcase_61 AC 251 ms
137,712 KB
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 AC 81 ms
76,156 KB
testcase_67 AC 79 ms
76,356 KB
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 AC 101 ms
79,244 KB
testcase_76 WA -
testcase_77 AC 185 ms
109,112 KB
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 83 ms
77,368 KB
testcase_83 AC 179 ms
109,596 KB
testcase_84 AC 248 ms
126,788 KB
testcase_85 WA -
testcase_86 WA -
testcase_87 WA -
testcase_88 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
INF = 1 << 60
MOD = 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()

prime = 998244353
root = 3
def _fmt(A, inverse = False):
    N = len(A)
    logN = (N - 1).bit_length()
    base = pow(root, (prime - 1) // N * (1 - 2 * inverse) % (prime - 1), prime)
    step = N
    for k in range(logN):
        step >>= 1
        w = pow(base, step, prime)
        wj = 1
        nA = [0] * N
        for j in range(1 << k):
            for i in range(1 << logN - k - 1):
                s, t = i + j * step, i + j * step + (N >> 1)
                ps, pt = i + j * step * 2, i + j * step * 2 + step
                nA[s], nA[t] = (A[ps] + A[pt] * wj) % prime, (A[ps] - A[pt] * wj) % prime
            wj = (wj * w) % prime
        A = nA
    return A

def convolution(f, g):
    N = 1 << (len(f) + len(g) - 2).bit_length()
    Ff, Fg = _fmt(f + [0] * (N - len(f))), _fmt(g + [0] * (N - len(g)))
    N_inv = pow(N, prime - 2, prime)
    fg = _fmt([a * b % prime * N_inv % prime for a, b in zip(Ff, Fg)], inverse = True)
    del fg[len(f) + len(g) - 1:]
    return fg

def resolve():
    n = int(input())
    N = 3 * n
    primes = []
    sieve = list(range(N + 1))
    for i in range(2, N + 1):
        if sieve[i] == i:
            primes.append(i)
        for p in primes:
            if sieve[i] < p or i * p > N:
                break
            sieve[i * p] = p

    f = [0] * (n + 1)
    g = [0] * (2 * n + 1)
    for p in primes:
        if p <= n:
            f[p] += 1
            g[p * 2] += 1

    a = 0
    f3 = convolution(f, convolution(f, f))
    for p in primes:
        a += f3[p]

    b = 0
    fg = convolution(f, g)
    for p in primes:
        b += fg[p]

    ans = (a - 3 * b) * pow(6, MOD - 2, MOD) % MOD
    print(ans)
resolve()
0