結果

問題 No.1261 数字集め
ユーザー mkawa2mkawa2
提出日時 2021-08-29 11:18:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,105 ms / 8,000 ms
コード長 1,940 bytes
コンパイル時間 658 ms
コンパイル使用メモリ 86,744 KB
実行使用メモリ 271,972 KB
最終ジャッジ日時 2023-08-14 09:05:46
合計ジャッジ時間 46,590 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,105 ms
259,948 KB
testcase_01 AC 154 ms
130,136 KB
testcase_02 AC 292 ms
182,916 KB
testcase_03 AC 220 ms
183,156 KB
testcase_04 AC 217 ms
175,132 KB
testcase_05 AC 307 ms
251,080 KB
testcase_06 AC 199 ms
185,112 KB
testcase_07 AC 277 ms
216,000 KB
testcase_08 AC 164 ms
141,936 KB
testcase_09 AC 205 ms
194,788 KB
testcase_10 AC 78 ms
78,016 KB
testcase_11 AC 337 ms
252,288 KB
testcase_12 AC 280 ms
232,896 KB
testcase_13 AC 277 ms
228,748 KB
testcase_14 AC 90 ms
89,004 KB
testcase_15 AC 191 ms
139,116 KB
testcase_16 AC 256 ms
214,552 KB
testcase_17 AC 242 ms
206,064 KB
testcase_18 AC 169 ms
138,632 KB
testcase_19 AC 257 ms
183,020 KB
testcase_20 AC 102 ms
93,076 KB
testcase_21 AC 332 ms
271,972 KB
testcase_22 AC 364 ms
270,932 KB
testcase_23 AC 354 ms
270,712 KB
testcase_24 AC 359 ms
260,124 KB
testcase_25 AC 328 ms
259,076 KB
testcase_26 AC 320 ms
259,048 KB
testcase_27 AC 315 ms
259,304 KB
testcase_28 AC 312 ms
260,016 KB
testcase_29 AC 312 ms
259,052 KB
testcase_30 AC 303 ms
259,716 KB
testcase_31 AC 309 ms
259,348 KB
testcase_32 AC 328 ms
259,832 KB
testcase_33 AC 358 ms
259,220 KB
testcase_34 AC 356 ms
259,772 KB
testcase_35 AC 358 ms
259,852 KB
testcase_36 AC 361 ms
259,092 KB
testcase_37 AC 315 ms
259,140 KB
testcase_38 AC 316 ms
259,036 KB
testcase_39 AC 317 ms
259,328 KB
testcase_40 AC 359 ms
260,016 KB
testcase_41 AC 356 ms
259,332 KB
testcase_42 AC 357 ms
260,012 KB
testcase_43 AC 314 ms
260,196 KB
testcase_44 AC 479 ms
247,576 KB
testcase_45 AC 342 ms
110,616 KB
testcase_46 AC 184 ms
182,948 KB
testcase_47 AC 366 ms
145,240 KB
testcase_48 AC 370 ms
213,536 KB
testcase_49 AC 390 ms
248,088 KB
testcase_50 AC 484 ms
229,020 KB
testcase_51 AC 196 ms
114,984 KB
testcase_52 AC 178 ms
79,412 KB
testcase_53 AC 320 ms
115,432 KB
testcase_54 AC 404 ms
120,520 KB
testcase_55 AC 244 ms
100,528 KB
testcase_56 AC 314 ms
106,100 KB
testcase_57 AC 383 ms
204,660 KB
testcase_58 AC 288 ms
110,356 KB
testcase_59 AC 513 ms
247,984 KB
testcase_60 AC 297 ms
119,696 KB
testcase_61 AC 311 ms
147,364 KB
testcase_62 AC 533 ms
227,312 KB
testcase_63 AC 163 ms
103,724 KB
testcase_64 AC 554 ms
250,880 KB
testcase_65 AC 328 ms
208,668 KB
testcase_66 AC 296 ms
194,832 KB
testcase_67 AC 288 ms
227,516 KB
testcase_68 AC 297 ms
184,532 KB
testcase_69 AC 240 ms
183,548 KB
testcase_70 AC 377 ms
159,900 KB
testcase_71 AC 467 ms
227,468 KB
testcase_72 AC 323 ms
128,164 KB
testcase_73 AC 334 ms
139,120 KB
testcase_74 AC 219 ms
105,360 KB
testcase_75 AC 410 ms
173,824 KB
testcase_76 AC 374 ms
204,876 KB
testcase_77 AC 397 ms
228,752 KB
testcase_78 AC 206 ms
79,032 KB
testcase_79 AC 381 ms
233,056 KB
testcase_80 AC 289 ms
80,584 KB
testcase_81 AC 237 ms
93,100 KB
testcase_82 AC 417 ms
192,336 KB
testcase_83 AC 395 ms
134,268 KB
testcase_84 AC 627 ms
260,428 KB
testcase_85 AC 640 ms
259,108 KB
testcase_86 AC 649 ms
259,608 KB
testcase_87 AC 689 ms
259,768 KB
testcase_88 AC 628 ms
259,504 KB
testcase_89 AC 609 ms
259,300 KB
testcase_90 AC 602 ms
259,264 KB
testcase_91 AC 598 ms
260,104 KB
testcase_92 AC 613 ms
259,080 KB
testcase_93 AC 612 ms
259,472 KB
権限があれば一括ダウンロードができます

ソースコード

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

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]

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+(m+1)*a*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)
    ans%=md
print(ans)

ot = [[] for _ in range(n+1)]
for _ in range(II()):
    x, y = LI()
    if y == n:
        for f in factors(x)[1:-1]+ot[x]:
            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
    if y < n: ot[y].append(x)
    print(ans)
0