結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,184 KB
testcase_01 AC 72 ms
71,028 KB
testcase_02 AC 72 ms
71,564 KB
testcase_03 AC 72 ms
71,500 KB
testcase_04 AC 76 ms
71,356 KB
testcase_05 AC 73 ms
71,308 KB
testcase_06 AC 80 ms
76,144 KB
testcase_07 AC 78 ms
76,432 KB
testcase_08 AC 81 ms
76,284 KB
testcase_09 AC 80 ms
76,432 KB
testcase_10 AC 81 ms
76,636 KB
testcase_11 AC 78 ms
76,472 KB
testcase_12 AC 79 ms
76,232 KB
testcase_13 AC 79 ms
76,204 KB
testcase_14 AC 79 ms
76,208 KB
testcase_15 AC 79 ms
76,392 KB
testcase_16 AC 80 ms
76,324 KB
testcase_17 AC 80 ms
76,544 KB
testcase_18 AC 79 ms
76,184 KB
testcase_19 AC 81 ms
76,520 KB
testcase_20 AC 90 ms
76,588 KB
testcase_21 AC 103 ms
77,648 KB
testcase_22 AC 101 ms
77,732 KB
testcase_23 AC 84 ms
76,688 KB
testcase_24 AC 82 ms
76,524 KB
testcase_25 AC 115 ms
79,364 KB
testcase_26 AC 111 ms
78,620 KB
testcase_27 AC 93 ms
77,448 KB
testcase_28 AC 94 ms
77,512 KB
testcase_29 AC 99 ms
77,528 KB
testcase_30 AC 98 ms
77,736 KB
testcase_31 AC 102 ms
77,560 KB
testcase_32 AC 109 ms
78,948 KB
testcase_33 AC 110 ms
78,848 KB
testcase_34 AC 110 ms
78,828 KB
testcase_35 AC 110 ms
78,652 KB
testcase_36 AC 110 ms
78,696 KB
testcase_37 AC 87 ms
76,876 KB
testcase_38 AC 86 ms
76,640 KB
testcase_39 AC 112 ms
78,832 KB
testcase_40 AC 100 ms
77,448 KB
testcase_41 AC 100 ms
77,800 KB
testcase_42 AC 100 ms
77,320 KB
testcase_43 AC 105 ms
77,776 KB
testcase_44 AC 102 ms
77,532 KB
testcase_45 AC 96 ms
77,352 KB
testcase_46 AC 96 ms
77,384 KB
testcase_47 AC 98 ms
77,408 KB
testcase_48 AC 117 ms
79,440 KB
testcase_49 AC 118 ms
79,336 KB
testcase_50 AC 102 ms
77,708 KB
testcase_51 AC 101 ms
77,732 KB
testcase_52 AC 92 ms
77,528 KB
testcase_53 AC 152 ms
99,456 KB
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 AC 206 ms
108,692 KB
testcase_58 AC 207 ms
108,728 KB
testcase_59 AC 152 ms
99,676 KB
testcase_60 AC 281 ms
138,060 KB
testcase_61 AC 281 ms
138,028 KB
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 AC 81 ms
76,584 KB
testcase_67 AC 82 ms
76,564 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 112 ms
79,344 KB
testcase_76 WA -
testcase_77 AC 206 ms
109,104 KB
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 96 ms
77,504 KB
testcase_83 AC 204 ms
109,796 KB
testcase_84 AC 275 ms
126,644 KB
testcase_85 WA -
testcase_86 WA -
testcase_87 WA -
testcase_88 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
INF = 1 << 60
MOD = 10**9 + 7 # 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