結果
問題 | No.1261 数字集め |
ユーザー | mkawa2 |
提出日時 | 2021-08-29 11:18:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,957 ms / 8,000 ms |
コード長 | 1,940 bytes |
コンパイル時間 | 160 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 268,888 KB |
最終ジャッジ日時 | 2024-11-22 04:33:14 |
合計ジャッジ時間 | 47,884 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2,957 ms
253,816 KB |
testcase_01 | AC | 189 ms
128,884 KB |
testcase_02 | AC | 230 ms
181,292 KB |
testcase_03 | AC | 230 ms
181,992 KB |
testcase_04 | AC | 202 ms
172,700 KB |
testcase_05 | AC | 328 ms
248,116 KB |
testcase_06 | AC | 216 ms
182,796 KB |
testcase_07 | AC | 233 ms
182,408 KB |
testcase_08 | AC | 157 ms
138,492 KB |
testcase_09 | AC | 223 ms
192,488 KB |
testcase_10 | AC | 101 ms
65,408 KB |
testcase_11 | AC | 379 ms
248,356 KB |
testcase_12 | AC | 311 ms
228,936 KB |
testcase_13 | AC | 243 ms
191,964 KB |
testcase_14 | AC | 69 ms
80,512 KB |
testcase_15 | AC | 152 ms
135,852 KB |
testcase_16 | AC | 232 ms
182,484 KB |
testcase_17 | AC | 231 ms
204,408 KB |
testcase_18 | AC | 154 ms
135,996 KB |
testcase_19 | AC | 230 ms
182,412 KB |
testcase_20 | AC | 74 ms
86,400 KB |
testcase_21 | AC | 355 ms
268,640 KB |
testcase_22 | AC | 348 ms
268,500 KB |
testcase_23 | AC | 339 ms
268,888 KB |
testcase_24 | AC | 343 ms
263,700 KB |
testcase_25 | AC | 342 ms
263,524 KB |
testcase_26 | AC | 341 ms
263,272 KB |
testcase_27 | AC | 343 ms
263,396 KB |
testcase_28 | AC | 342 ms
263,512 KB |
testcase_29 | AC | 342 ms
263,256 KB |
testcase_30 | AC | 342 ms
263,264 KB |
testcase_31 | AC | 344 ms
263,268 KB |
testcase_32 | AC | 345 ms
263,136 KB |
testcase_33 | AC | 344 ms
263,264 KB |
testcase_34 | AC | 343 ms
263,396 KB |
testcase_35 | AC | 343 ms
263,260 KB |
testcase_36 | AC | 346 ms
263,128 KB |
testcase_37 | AC | 342 ms
263,392 KB |
testcase_38 | AC | 341 ms
263,388 KB |
testcase_39 | AC | 344 ms
263,016 KB |
testcase_40 | AC | 344 ms
263,012 KB |
testcase_41 | AC | 346 ms
263,516 KB |
testcase_42 | AC | 345 ms
263,240 KB |
testcase_43 | AC | 345 ms
263,524 KB |
testcase_44 | AC | 556 ms
243,212 KB |
testcase_45 | AC | 385 ms
111,360 KB |
testcase_46 | AC | 210 ms
180,600 KB |
testcase_47 | AC | 389 ms
140,540 KB |
testcase_48 | AC | 404 ms
202,996 KB |
testcase_49 | AC | 446 ms
243,024 KB |
testcase_50 | AC | 572 ms
223,368 KB |
testcase_51 | AC | 194 ms
114,816 KB |
testcase_52 | AC | 191 ms
78,336 KB |
testcase_53 | AC | 317 ms
114,944 KB |
testcase_54 | AC | 419 ms
119,260 KB |
testcase_55 | AC | 250 ms
99,456 KB |
testcase_56 | AC | 334 ms
106,496 KB |
testcase_57 | AC | 423 ms
200,844 KB |
testcase_58 | AC | 297 ms
111,744 KB |
testcase_59 | AC | 603 ms
243,344 KB |
testcase_60 | AC | 322 ms
118,616 KB |
testcase_61 | AC | 338 ms
144,036 KB |
testcase_62 | AC | 623 ms
223,424 KB |
testcase_63 | AC | 165 ms
102,912 KB |
testcase_64 | AC | 631 ms
252,056 KB |
testcase_65 | AC | 372 ms
207,600 KB |
testcase_66 | AC | 323 ms
193,244 KB |
testcase_67 | AC | 367 ms
228,836 KB |
testcase_68 | AC | 339 ms
182,176 KB |
testcase_69 | AC | 287 ms
182,092 KB |
testcase_70 | AC | 430 ms
156,360 KB |
testcase_71 | AC | 556 ms
217,748 KB |
testcase_72 | AC | 361 ms
125,264 KB |
testcase_73 | AC | 352 ms
133,996 KB |
testcase_74 | AC | 226 ms
107,264 KB |
testcase_75 | AC | 442 ms
172,508 KB |
testcase_76 | AC | 413 ms
200,872 KB |
testcase_77 | AC | 452 ms
228,516 KB |
testcase_78 | AC | 209 ms
78,044 KB |
testcase_79 | AC | 447 ms
228,884 KB |
testcase_80 | AC | 292 ms
79,356 KB |
testcase_81 | AC | 244 ms
92,800 KB |
testcase_82 | AC | 458 ms
208,324 KB |
testcase_83 | AC | 408 ms
131,016 KB |
testcase_84 | AC | 732 ms
263,660 KB |
testcase_85 | AC | 742 ms
263,780 KB |
testcase_86 | AC | 731 ms
263,532 KB |
testcase_87 | AC | 712 ms
263,396 KB |
testcase_88 | AC | 733 ms
263,524 KB |
testcase_89 | AC | 703 ms
263,140 KB |
testcase_90 | AC | 704 ms
263,264 KB |
testcase_91 | AC | 706 ms
263,140 KB |
testcase_92 | AC | 691 ms
263,524 KB |
testcase_93 | AC | 729 ms
263,144 KB |
ソースコード
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)