結果

問題 No.3686 Coprime Sum
コンテスト
ユーザー Tuchmos
提出日時 2026-09-10 08:59:28
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 738 ms / 2,000 ms
+ 286µs
コード長 1,271 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 74 ms
コンパイル使用メモリ 80,512 KB
実行使用メモリ 239,872 KB
最終ジャッジ日時 2026-09-10 08:59:36
合計ジャッジ時間 7,891 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

###############################################################
#https://atcoder.jp/contests/abc249/submissions/71937223
import math

def smallest_prime_facror(n):
    res=list(range(n+1))
    for i in range(2,int(math.isqrt(n))+1):
        if res[i]==i:
            for j in range(i*i,n+1,i):
                if res[j]==j:
                    res[j]=i
    return res

spf=smallest_prime_facror(10000000)

def prime_factorization(n):
    factors={}
    current=n
    while current>1:
        factors[spf[current]]=factors.get(spf[current],0)+1
        current//=spf[current]
    return factors

def divisors(n):
    factors=prime_factorization(n)
    divs=[1]
    for p,e in factors.items():
        m=len(divs)
        mul=1
        for _ in range(e):
            mul*=p
            for i in range(m):
                divs.append(divs[i]*mul)
    return divs

###############################################################

N,M=map(int,input().split())
meb=[0]*(10000001)
meb[1]=1
mod=998244353
inv=pow(4,-1,mod)
ans=N*M*(N+1)*(M+1)*inv%mod
for d in range(2,min(N,M)+1):
    p=spf[d]
    if d%(p*p)==0:
        meb[d]=0
        continue

    m=-meb[d//p]
    nd=N//d
    md=M//d
    ad=m*d*d*nd*md*(nd+1)*(md+1)*inv%mod
    ans+=ad
    ans%=mod
    meb[d]=m

print(ans)
0