結果

問題 No.1261 数字集め
ユーザー mkawa2mkawa2
提出日時 2021-08-29 11:19:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,831 ms / 8,000 ms
コード長 1,944 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 269,024 KB
最終ジャッジ日時 2024-05-01 21:43:36
合計ジャッジ時間 46,021 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,831 ms
253,940 KB
testcase_01 AC 179 ms
129,188 KB
testcase_02 AC 216 ms
181,676 KB
testcase_03 AC 212 ms
182,508 KB
testcase_04 AC 192 ms
172,952 KB
testcase_05 AC 311 ms
248,248 KB
testcase_06 AC 203 ms
183,192 KB
testcase_07 AC 219 ms
182,660 KB
testcase_08 AC 157 ms
138,516 KB
testcase_09 AC 208 ms
192,872 KB
testcase_10 AC 51 ms
65,280 KB
testcase_11 AC 459 ms
248,484 KB
testcase_12 AC 325 ms
228,936 KB
testcase_13 AC 291 ms
192,224 KB
testcase_14 AC 70 ms
80,896 KB
testcase_15 AC 153 ms
135,600 KB
testcase_16 AC 221 ms
182,488 KB
testcase_17 AC 226 ms
204,532 KB
testcase_18 AC 148 ms
135,936 KB
testcase_19 AC 220 ms
182,156 KB
testcase_20 AC 69 ms
87,040 KB
testcase_21 AC 319 ms
269,024 KB
testcase_22 AC 318 ms
269,016 KB
testcase_23 AC 322 ms
268,892 KB
testcase_24 AC 343 ms
263,648 KB
testcase_25 AC 346 ms
263,780 KB
testcase_26 AC 328 ms
263,260 KB
testcase_27 AC 340 ms
263,772 KB
testcase_28 AC 339 ms
263,136 KB
testcase_29 AC 342 ms
263,528 KB
testcase_30 AC 395 ms
263,136 KB
testcase_31 AC 288 ms
263,396 KB
testcase_32 AC 288 ms
263,400 KB
testcase_33 AC 302 ms
263,388 KB
testcase_34 AC 286 ms
263,524 KB
testcase_35 AC 284 ms
263,776 KB
testcase_36 AC 282 ms
263,652 KB
testcase_37 AC 277 ms
263,528 KB
testcase_38 AC 281 ms
263,784 KB
testcase_39 AC 280 ms
263,132 KB
testcase_40 AC 280 ms
263,516 KB
testcase_41 AC 283 ms
263,656 KB
testcase_42 AC 280 ms
263,396 KB
testcase_43 AC 278 ms
263,900 KB
testcase_44 AC 500 ms
243,328 KB
testcase_45 AC 350 ms
111,872 KB
testcase_46 AC 191 ms
180,952 KB
testcase_47 AC 371 ms
140,292 KB
testcase_48 AC 379 ms
203,260 KB
testcase_49 AC 403 ms
243,312 KB
testcase_50 AC 534 ms
223,108 KB
testcase_51 AC 181 ms
114,944 KB
testcase_52 AC 178 ms
78,552 KB
testcase_53 AC 308 ms
114,816 KB
testcase_54 AC 411 ms
119,128 KB
testcase_55 AC 239 ms
99,584 KB
testcase_56 AC 317 ms
107,008 KB
testcase_57 AC 396 ms
201,232 KB
testcase_58 AC 279 ms
111,872 KB
testcase_59 AC 559 ms
243,336 KB
testcase_60 AC 308 ms
118,480 KB
testcase_61 AC 316 ms
144,312 KB
testcase_62 AC 578 ms
225,756 KB
testcase_63 AC 152 ms
103,424 KB
testcase_64 AC 594 ms
252,556 KB
testcase_65 AC 347 ms
207,464 KB
testcase_66 AC 302 ms
193,116 KB
testcase_67 AC 311 ms
228,704 KB
testcase_68 AC 304 ms
181,928 KB
testcase_69 AC 256 ms
182,220 KB
testcase_70 AC 413 ms
156,328 KB
testcase_71 AC 494 ms
218,264 KB
testcase_72 AC 349 ms
125,524 KB
testcase_73 AC 333 ms
134,384 KB
testcase_74 AC 218 ms
106,752 KB
testcase_75 AC 433 ms
172,508 KB
testcase_76 AC 387 ms
200,924 KB
testcase_77 AC 418 ms
228,776 KB
testcase_78 AC 193 ms
78,168 KB
testcase_79 AC 401 ms
229,136 KB
testcase_80 AC 281 ms
79,864 KB
testcase_81 AC 234 ms
92,800 KB
testcase_82 AC 429 ms
208,316 KB
testcase_83 AC 389 ms
131,148 KB
testcase_84 AC 649 ms
263,272 KB
testcase_85 AC 668 ms
263,664 KB
testcase_86 AC 682 ms
263,656 KB
testcase_87 AC 727 ms
263,140 KB
testcase_88 AC 659 ms
263,344 KB
testcase_89 AC 625 ms
263,652 KB
testcase_90 AC 632 ms
263,396 KB
testcase_91 AC 633 ms
263,108 KB
testcase_92 AC 645 ms
263,436 KB
testcase_93 AC 646 ms
263,140 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