結果

問題 No.3686 Coprime Sum
コンテスト
ユーザー detteiuu
提出日時 2026-09-06 22:02:05
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 1,394 ms / 2,000 ms
+ 54µs
コード長 823 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 240 ms
コンパイル使用メモリ 96,076 KB
実行使用メモリ 240,384 KB
最終ジャッジ日時 2026-09-06 22:02:21
合計ジャッジ時間 9,245 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

class Eratosthenes:
    def __init__(self, n):
        self.isPrime = [True]*(n+1)
        self.isPrime[0], self.isPrime[1] = False, False
        self.mobius = [1]*(n+1)
        for i in range(2, n+1):
            if self.isPrime[i]:
                self.mobius[i] = -1
                for j in range(i*2, n+1, i):
                    self.isPrime[j] = False
                    if j//i%i == 0:
                        self.mobius[j] = 0
                    else:
                        self.mobius[j] *= -1

MOD = 998244353

half = pow(2, -1, MOD)
def rangeSUM(l, r, c):
    return (l+r)%MOD*c%MOD*half%MOD

N, M = map(int, input().split())

MIN = min(N, M)

E = Eratosthenes(MIN)
ans = 0
for n in range(1, MIN+1):
    ans += rangeSUM(n, N//n*n, N//n)*rangeSUM(n, M//n*n, M//n)%MOD*E.mobius[n]
    ans %= MOD

print(ans)
0