結果

問題 No.886 Direct
ユーザー shotoyooshotoyoo
提出日時 2020-11-21 15:45:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,353 ms / 4,000 ms
コード長 1,127 bytes
コンパイル時間 918 ms
コンパイル使用メモリ 86,880 KB
実行使用メモリ 324,504 KB
最終ジャッジ日時 2023-09-30 21:55:28
合計ジャッジ時間 13,254 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,236 KB
testcase_01 AC 71 ms
71,388 KB
testcase_02 AC 71 ms
71,384 KB
testcase_03 AC 94 ms
77,220 KB
testcase_04 AC 71 ms
71,420 KB
testcase_05 AC 73 ms
71,264 KB
testcase_06 AC 72 ms
71,200 KB
testcase_07 AC 71 ms
71,092 KB
testcase_08 AC 72 ms
71,288 KB
testcase_09 AC 72 ms
71,436 KB
testcase_10 AC 73 ms
71,404 KB
testcase_11 AC 71 ms
71,276 KB
testcase_12 AC 72 ms
71,448 KB
testcase_13 AC 72 ms
71,224 KB
testcase_14 AC 72 ms
71,348 KB
testcase_15 AC 72 ms
71,244 KB
testcase_16 AC 72 ms
71,288 KB
testcase_17 AC 87 ms
76,588 KB
testcase_18 AC 98 ms
77,656 KB
testcase_19 AC 97 ms
77,376 KB
testcase_20 AC 93 ms
76,516 KB
testcase_21 AC 87 ms
76,232 KB
testcase_22 AC 98 ms
77,568 KB
testcase_23 AC 204 ms
101,716 KB
testcase_24 AC 395 ms
141,196 KB
testcase_25 AC 188 ms
98,892 KB
testcase_26 AC 171 ms
93,888 KB
testcase_27 AC 696 ms
193,176 KB
testcase_28 AC 694 ms
194,524 KB
testcase_29 AC 72 ms
71,436 KB
testcase_30 AC 72 ms
71,424 KB
testcase_31 AC 1,305 ms
324,504 KB
testcase_32 AC 1,348 ms
324,164 KB
testcase_33 AC 1,353 ms
324,408 KB
testcase_34 AC 1,353 ms
323,852 KB
testcase_35 AC 1,337 ms
323,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

h,w = list(map(int, input().split()))
m = min(h,w)
f = [0]*(m+1)
M = 10**9+7
def subh(k):
    num = h//k
    return h*num - (k + num*k)*num//2
def subw(k):
    num = w//k
    return w*num - (k + num*k)*num//2
def hurui(n):
    """線形篩
    pl: 素数のリスト
    mpf: iを割り切る最小の素因数
    """
    pl = []
    mpf = [None]*(n+1)
    for d in range(2,n):
        if mpf[d] is None:
            mpf[d] = d
            pl.append(d)
        for p in pl:
            if p*d>n or p>mpf[d]:
                break
            mpf[p*d] = p
    return pl, mpf
_,mpf = hurui(m+1)
# pl.insert(0,1)
for p in range(m, 0, -1):
    f[p] += subh(p)*subw(p)
    if mpf[p]!=p:
        continue
    num = m//p
    for k in range(1,num+1):
        f[k] -= f[k*p]
        f[k] %= M
# for k in range(m, 0, -1):
#     f[k] = subh(k)*subw(k)
#     for i in range(2*k, m+1, k):
#         f[k] -= f[i]
#         f[k] %= M
#     f[k] %= M
ans = (f[1]*2 + (h-1)*w + h*(w-1))%M
print(ans%M)
0