結果

問題 No.1261 数字集め
ユーザー mkawa2mkawa2
提出日時 2021-08-27 21:00:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,912 bytes
コンパイル時間 1,503 ms
コンパイル使用メモリ 86,404 KB
実行使用メモリ 364,028 KB
最終ジャッジ日時 2023-08-13 07:02:51
合計ジャッジ時間 64,784 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 278 ms
127,480 KB
testcase_02 AC 539 ms
178,128 KB
testcase_03 WA -
testcase_04 AC 242 ms
148,420 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 143 ms
78,940 KB
testcase_11 AC 488 ms
219,596 KB
testcase_12 AC 287 ms
199,752 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 352 ms
179,896 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 293 ms
178,108 KB
testcase_20 WA -
testcase_21 AC 468 ms
239,940 KB
testcase_22 AC 337 ms
240,372 KB
testcase_23 AC 355 ms
239,732 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 577 ms
224,800 KB
testcase_45 WA -
testcase_46 AC 206 ms
156,400 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 258 ms
114,656 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 AC 280 ms
170,388 KB
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 WA -
testcase_83 WA -
testcase_84 WA -
testcase_85 WA -
testcase_86 WA -
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 WA -
testcase_93 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
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 = 10**9
# md = 998244353
md = 10**9+7

from functools import lru_cache

def factors(a):
    if a <= 0: return [0]
    dd0, dd1 = [], []
    for d in range(1, a+1):
        if d*d > a: break
        if a%d: continue
        dd0.append(d)
        dd1.append(a//d)
    if dd0[-1] == dd1[-1]: dd1.pop()
    return dd0+dd1[::-1]

@lru_cache(None)
def cal(a, b):
    c = aa[-1]-1
    if a == b == c:
        return pow(b[0], m, md)*((m+2)*(m+1)//2)%md
    if a == c: b, c = c, b
    if b == c: a, c = c, a
    if a == b:
        am = pow(a, m+1, md)
        return (-c*(m+2)*am%md+a*(m+1)*am%md+pow(c, m+2, md))*pow(a-c, 2*md-4, md)%md
    return (pow(a, m+2, md)*(b-c)+pow(c, m+1, md)*(a*c-b*c)+pow(b, m+1, md)*(-a*b+b*c))*pow((a-b)*(a-c)*(b-c), md-2,
                                                                                            md)%md
n, m = LI()
m -= 3
aa = [0, 0]+LI()

ff = factors(n)[1:-1]
ton = [False]*(n+1)
ans = 0
for i, f in enumerate(ff):
    ton[f] = True
    for g in ff[i+1:]:
        if g%f: continue
        ans += cal(aa[f]-1, aa[g]-1)
        # print(f,g,ans)
print(ans)

for _ in range(II()):
    x, y = LI()
    if y == n:
        for f in factors(x)[1:-1]:
            ans = (ans+cal(aa[f]-1, aa[x]-1))%md
        ton[x] = True
    elif ton[y]:
        ans = (ans+cal(aa[x]-1, aa[y]-1))%md
    print(ans)
0