結果

問題 No.886 Direct
ユーザー mkawa2mkawa2
提出日時 2023-05-02 21:46:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 860 ms / 4,000 ms
コード長 2,429 bytes
コンパイル時間 455 ms
コンパイル使用メモリ 82,144 KB
実行使用メモリ 261,088 KB
最終ジャッジ日時 2024-05-01 07:22:47
合計ジャッジ時間 11,459 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,992 KB
testcase_01 AC 42 ms
52,736 KB
testcase_02 AC 41 ms
52,352 KB
testcase_03 AC 65 ms
67,840 KB
testcase_04 AC 42 ms
52,736 KB
testcase_05 AC 41 ms
52,864 KB
testcase_06 AC 41 ms
52,608 KB
testcase_07 AC 42 ms
53,120 KB
testcase_08 AC 40 ms
52,352 KB
testcase_09 AC 42 ms
52,864 KB
testcase_10 AC 41 ms
52,608 KB
testcase_11 AC 39 ms
52,736 KB
testcase_12 AC 40 ms
52,736 KB
testcase_13 AC 40 ms
52,352 KB
testcase_14 AC 41 ms
52,608 KB
testcase_15 AC 40 ms
52,864 KB
testcase_16 AC 40 ms
52,992 KB
testcase_17 AC 64 ms
68,352 KB
testcase_18 AC 67 ms
68,608 KB
testcase_19 AC 63 ms
68,736 KB
testcase_20 AC 63 ms
67,640 KB
testcase_21 AC 69 ms
69,632 KB
testcase_22 AC 68 ms
69,120 KB
testcase_23 AC 412 ms
234,240 KB
testcase_24 AC 443 ms
239,664 KB
testcase_25 AC 246 ms
175,924 KB
testcase_26 AC 354 ms
216,320 KB
testcase_27 AC 760 ms
251,096 KB
testcase_28 AC 738 ms
248,936 KB
testcase_29 AC 820 ms
243,892 KB
testcase_30 AC 814 ms
244,236 KB
testcase_31 AC 860 ms
261,088 KB
testcase_32 AC 819 ms
244,112 KB
testcase_33 AC 808 ms
244,292 KB
testcase_34 AC 824 ms
243,908 KB
testcase_35 AC 824 ms
243,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
md = 10**9+7
# md = 998244353

class Sieve:
    def __init__(self, n):
        self.plist = [2]
        min_prime_factor = [2, 0]*(n//2+1)
        for x in range(3, n+1, 2):
            if min_prime_factor[x] == 0:
                min_prime_factor[x] = x
                self.plist.append(x)
                if x**2 > n: continue
                for y in range(x**2, n+1, 2*x):
                    if min_prime_factor[y] == 0:
                        min_prime_factor[y] = x
        self.min_prime_factor = min_prime_factor

    def isprime(self, x):
        return self.min_prime_factor[x] == x

    def pf(self, x):
        pp, ee = [], []
        while x > 1:
            mpf = self.min_prime_factor[x]
            if pp and mpf == pp[-1]:
                ee[-1] += 1
            else:
                pp.append(mpf)
                ee.append(1)
            x //= mpf
        return pp, ee

    # unsorted
    def factor(self, a):
        ff = [1]
        pp, ee = self.pf(a)
        for p, e in zip(pp, ee):
            ff, gg = [], ff
            w = p
            for _ in range(e):
                for f in gg: ff.append(f*w)
                w *= p
            ff += gg
        return ff

h, w = LI()

if h == w == 1:
    print(0)
    exit()

if h > w: h, w = w, h

sv = Sieve(w)

aa = [h-i for i in range(h)]
bb = [w-i for i in range(w)]
aa += [0]*(w-h)
aa[0] = bb[0] = 0

for p in sv.plist:
    for i in range((w-1)//p, 0, -1):
        aa[i] += aa[i*p]
        bb[i] += bb[i*p]
        aa[i] %= md
        bb[i] %= md

cc = [a*b%md for a, b in zip(aa, bb)]
for p in sv.plist:
    for i in range((w-1)//p, 0, -1)[::-1]:
        cc[i] -= cc[i*p]
        cc[i] %= md

ans = cc[1]*2+(h-1)*w+h*(w-1)
print(ans%md)
0