結果

問題 No.3691 Calculate Mu Sum
コンテスト
ユーザー Rino-program
提出日時 2026-09-06 22:53:12
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 961 ms / 2,000 ms
+ 567µs
コード長 555 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 233 ms
コンパイル使用メモリ 96,212 KB
実行使用メモリ 631,808 KB
最終ジャッジ日時 2026-09-06 22:53:24
合計ジャッジ時間 6,496 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# https://tjkendev.github.io/procon-library/python/prime/moebius-function.html
# a table of μ(n) for n in [1, N]
# O(N log log N)
def moebius_table(n):
    *p, = range(n+1)
    sq = int(n**.5)
    for x in range(2, sq+1):
        if p[x] == x:
            for y in range(x*x, n+1, x):
                p[y] = x
            for y in range(x*x, n+1, x*x):
                p[y] = 0
    res = [0]*(n+1)
    res[0] = 0; res[1] = 1
    for x in range(2, n+1):
        res[x] = (p[x] and -res[x//p[x]])
    return res

print(sum(moebius_table(int(input()))[1:]))
0