結果

問題 No.1261 数字集め
ユーザー mkawa2mkawa2
提出日時 2021-08-29 11:19:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,932 ms / 8,000 ms
コード長 1,944 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 86,732 KB
実行使用メモリ 271,524 KB
最終ジャッジ日時 2023-08-14 09:07:22
合計ジャッジ時間 47,046 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,932 ms
259,112 KB
testcase_01 AC 157 ms
130,560 KB
testcase_02 AC 231 ms
182,744 KB
testcase_03 AC 231 ms
183,128 KB
testcase_04 AC 204 ms
174,700 KB
testcase_05 AC 295 ms
251,388 KB
testcase_06 AC 209 ms
184,856 KB
testcase_07 AC 271 ms
214,268 KB
testcase_08 AC 166 ms
141,924 KB
testcase_09 AC 212 ms
195,120 KB
testcase_10 AC 80 ms
78,068 KB
testcase_11 AC 290 ms
251,408 KB
testcase_12 AC 284 ms
232,556 KB
testcase_13 AC 280 ms
227,100 KB
testcase_14 AC 94 ms
89,104 KB
testcase_15 AC 161 ms
138,896 KB
testcase_16 AC 272 ms
214,016 KB
testcase_17 AC 218 ms
206,424 KB
testcase_18 AC 160 ms
138,692 KB
testcase_19 AC 228 ms
182,692 KB
testcase_20 AC 97 ms
93,300 KB
testcase_21 AC 310 ms
270,868 KB
testcase_22 AC 314 ms
271,524 KB
testcase_23 AC 313 ms
271,424 KB
testcase_24 AC 337 ms
259,560 KB
testcase_25 AC 335 ms
259,580 KB
testcase_26 AC 337 ms
260,316 KB
testcase_27 AC 338 ms
260,848 KB
testcase_28 AC 338 ms
259,472 KB
testcase_29 AC 338 ms
260,824 KB
testcase_30 AC 335 ms
259,552 KB
testcase_31 AC 338 ms
260,544 KB
testcase_32 AC 333 ms
259,028 KB
testcase_33 AC 333 ms
259,472 KB
testcase_34 AC 334 ms
259,620 KB
testcase_35 AC 332 ms
259,632 KB
testcase_36 AC 334 ms
260,264 KB
testcase_37 AC 339 ms
259,776 KB
testcase_38 AC 337 ms
259,216 KB
testcase_39 AC 337 ms
259,824 KB
testcase_40 AC 335 ms
259,924 KB
testcase_41 AC 340 ms
259,276 KB
testcase_42 AC 334 ms
259,408 KB
testcase_43 AC 337 ms
259,528 KB
testcase_44 AC 527 ms
248,076 KB
testcase_45 AC 391 ms
110,260 KB
testcase_46 AC 212 ms
182,736 KB
testcase_47 AC 408 ms
145,576 KB
testcase_48 AC 409 ms
213,760 KB
testcase_49 AC 412 ms
247,380 KB
testcase_50 AC 545 ms
227,500 KB
testcase_51 AC 220 ms
114,828 KB
testcase_52 AC 200 ms
79,292 KB
testcase_53 AC 362 ms
115,644 KB
testcase_54 AC 451 ms
120,596 KB
testcase_55 AC 279 ms
100,568 KB
testcase_56 AC 359 ms
106,340 KB
testcase_57 AC 431 ms
205,048 KB
testcase_58 AC 329 ms
110,448 KB
testcase_59 AC 572 ms
246,872 KB
testcase_60 AC 336 ms
119,740 KB
testcase_61 AC 358 ms
147,308 KB
testcase_62 AC 619 ms
227,516 KB
testcase_63 AC 186 ms
103,824 KB
testcase_64 AC 623 ms
252,312 KB
testcase_65 AC 362 ms
208,640 KB
testcase_66 AC 330 ms
194,596 KB
testcase_67 AC 326 ms
227,500 KB
testcase_68 AC 325 ms
184,396 KB
testcase_69 AC 273 ms
183,712 KB
testcase_70 AC 427 ms
159,996 KB
testcase_71 AC 513 ms
227,252 KB
testcase_72 AC 358 ms
128,204 KB
testcase_73 AC 379 ms
139,212 KB
testcase_74 AC 243 ms
105,300 KB
testcase_75 AC 459 ms
173,560 KB
testcase_76 AC 409 ms
205,348 KB
testcase_77 AC 422 ms
227,564 KB
testcase_78 AC 233 ms
79,432 KB
testcase_79 AC 413 ms
232,136 KB
testcase_80 AC 320 ms
80,556 KB
testcase_81 AC 254 ms
93,180 KB
testcase_82 AC 452 ms
192,120 KB
testcase_83 AC 418 ms
134,260 KB
testcase_84 AC 676 ms
259,316 KB
testcase_85 AC 679 ms
259,468 KB
testcase_86 AC 688 ms
260,260 KB
testcase_87 AC 672 ms
259,644 KB
testcase_88 AC 687 ms
260,072 KB
testcase_89 AC 660 ms
259,488 KB
testcase_90 AC 666 ms
259,516 KB
testcase_91 AC 661 ms
260,328 KB
testcase_92 AC 675 ms
259,588 KB
testcase_93 AC 667 ms
259,596 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