結果
問題 | No.1261 数字集め |
ユーザー | mkawa2 |
提出日時 | 2021-08-29 11:19:52 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,950 ms / 8,000 ms |
コード長 | 1,944 bytes |
コンパイル時間 | 441 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 268,644 KB |
最終ジャッジ日時 | 2024-11-22 04:35:46 |
合計ジャッジ時間 | 47,313 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2,950 ms
253,944 KB |
testcase_01 | AC | 175 ms
129,136 KB |
testcase_02 | AC | 232 ms
181,808 KB |
testcase_03 | AC | 233 ms
181,992 KB |
testcase_04 | AC | 202 ms
173,080 KB |
testcase_05 | AC | 328 ms
248,504 KB |
testcase_06 | AC | 214 ms
182,932 KB |
testcase_07 | AC | 233 ms
182,404 KB |
testcase_08 | AC | 155 ms
138,104 KB |
testcase_09 | AC | 219 ms
192,492 KB |
testcase_10 | AC | 54 ms
65,152 KB |
testcase_11 | AC | 343 ms
248,356 KB |
testcase_12 | AC | 383 ms
229,060 KB |
testcase_13 | AC | 248 ms
192,096 KB |
testcase_14 | AC | 69 ms
80,512 KB |
testcase_15 | AC | 154 ms
135,988 KB |
testcase_16 | AC | 238 ms
182,488 KB |
testcase_17 | AC | 234 ms
204,416 KB |
testcase_18 | AC | 156 ms
135,704 KB |
testcase_19 | AC | 234 ms
182,152 KB |
testcase_20 | AC | 76 ms
86,528 KB |
testcase_21 | AC | 340 ms
268,644 KB |
testcase_22 | AC | 340 ms
268,512 KB |
testcase_23 | AC | 341 ms
268,384 KB |
testcase_24 | AC | 344 ms
263,652 KB |
testcase_25 | AC | 341 ms
263,404 KB |
testcase_26 | AC | 340 ms
263,388 KB |
testcase_27 | AC | 338 ms
263,132 KB |
testcase_28 | AC | 342 ms
263,128 KB |
testcase_29 | AC | 344 ms
263,248 KB |
testcase_30 | AC | 344 ms
263,244 KB |
testcase_31 | AC | 343 ms
263,264 KB |
testcase_32 | AC | 341 ms
263,388 KB |
testcase_33 | AC | 342 ms
263,140 KB |
testcase_34 | AC | 344 ms
263,396 KB |
testcase_35 | AC | 343 ms
263,652 KB |
testcase_36 | AC | 341 ms
263,272 KB |
testcase_37 | AC | 342 ms
263,392 KB |
testcase_38 | AC | 340 ms
263,524 KB |
testcase_39 | AC | 344 ms
263,644 KB |
testcase_40 | AC | 343 ms
263,132 KB |
testcase_41 | AC | 340 ms
263,644 KB |
testcase_42 | AC | 343 ms
263,268 KB |
testcase_43 | AC | 340 ms
263,516 KB |
testcase_44 | AC | 552 ms
243,496 KB |
testcase_45 | AC | 366 ms
111,488 KB |
testcase_46 | AC | 214 ms
180,664 KB |
testcase_47 | AC | 394 ms
140,540 KB |
testcase_48 | AC | 413 ms
203,120 KB |
testcase_49 | AC | 451 ms
243,280 KB |
testcase_50 | AC | 567 ms
222,984 KB |
testcase_51 | AC | 194 ms
114,560 KB |
testcase_52 | AC | 180 ms
78,720 KB |
testcase_53 | AC | 319 ms
114,688 KB |
testcase_54 | AC | 426 ms
119,084 KB |
testcase_55 | AC | 254 ms
99,712 KB |
testcase_56 | AC | 334 ms
106,496 KB |
testcase_57 | AC | 429 ms
201,100 KB |
testcase_58 | AC | 301 ms
111,744 KB |
testcase_59 | AC | 602 ms
243,340 KB |
testcase_60 | AC | 316 ms
118,484 KB |
testcase_61 | AC | 341 ms
144,080 KB |
testcase_62 | AC | 626 ms
223,292 KB |
testcase_63 | AC | 160 ms
103,040 KB |
testcase_64 | AC | 634 ms
252,316 KB |
testcase_65 | AC | 373 ms
207,212 KB |
testcase_66 | AC | 329 ms
192,984 KB |
testcase_67 | AC | 357 ms
228,704 KB |
testcase_68 | AC | 324 ms
182,040 KB |
testcase_69 | AC | 274 ms
181,968 KB |
testcase_70 | AC | 425 ms
156,440 KB |
testcase_71 | AC | 525 ms
217,620 KB |
testcase_72 | AC | 348 ms
125,008 KB |
testcase_73 | AC | 357 ms
134,244 KB |
testcase_74 | AC | 229 ms
106,752 KB |
testcase_75 | AC | 451 ms
172,512 KB |
testcase_76 | AC | 420 ms
200,880 KB |
testcase_77 | AC | 456 ms
228,652 KB |
testcase_78 | AC | 207 ms
77,660 KB |
testcase_79 | AC | 451 ms
228,756 KB |
testcase_80 | AC | 290 ms
79,612 KB |
testcase_81 | AC | 237 ms
92,928 KB |
testcase_82 | AC | 461 ms
208,452 KB |
testcase_83 | AC | 403 ms
131,020 KB |
testcase_84 | AC | 720 ms
263,136 KB |
testcase_85 | AC | 747 ms
263,776 KB |
testcase_86 | AC | 717 ms
263,524 KB |
testcase_87 | AC | 684 ms
263,144 KB |
testcase_88 | AC | 708 ms
263,396 KB |
testcase_89 | AC | 675 ms
263,264 KB |
testcase_90 | AC | 679 ms
263,396 KB |
testcase_91 | AC | 683 ms
263,656 KB |
testcase_92 | AC | 695 ms
263,400 KB |
testcase_93 | AC | 692 ms
263,272 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)