結果
問題 | No.187 中華風 (Hard) |
ユーザー | akasia_midori |
提出日時 | 2023-11-23 02:13:25 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 663 ms / 3,000 ms |
コード長 | 2,495 bytes |
コンパイル時間 | 363 ms |
コンパイル使用メモリ | 81,700 KB |
実行使用メモリ | 76,708 KB |
最終ジャッジ日時 | 2023-11-23 02:13:36 |
合計ジャッジ時間 | 11,172 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 57 ms
64,028 KB |
testcase_01 | AC | 56 ms
64,028 KB |
testcase_02 | AC | 559 ms
76,680 KB |
testcase_03 | AC | 522 ms
76,676 KB |
testcase_04 | AC | 548 ms
76,416 KB |
testcase_05 | AC | 517 ms
76,276 KB |
testcase_06 | AC | 525 ms
76,404 KB |
testcase_07 | AC | 523 ms
76,276 KB |
testcase_08 | AC | 636 ms
73,464 KB |
testcase_09 | AC | 637 ms
73,464 KB |
testcase_10 | AC | 663 ms
73,464 KB |
testcase_11 | AC | 521 ms
76,420 KB |
testcase_12 | AC | 521 ms
76,276 KB |
testcase_13 | AC | 457 ms
73,092 KB |
testcase_14 | AC | 455 ms
73,372 KB |
testcase_15 | AC | 505 ms
76,420 KB |
testcase_16 | AC | 489 ms
76,548 KB |
testcase_17 | AC | 41 ms
59,604 KB |
testcase_18 | AC | 54 ms
63,772 KB |
testcase_19 | AC | 41 ms
59,604 KB |
testcase_20 | AC | 472 ms
76,708 KB |
testcase_21 | AC | 42 ms
59,604 KB |
testcase_22 | AC | 522 ms
76,428 KB |
testcase_23 | AC | 38 ms
53,844 KB |
testcase_24 | AC | 41 ms
59,604 KB |
ソースコード
def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append((i, cnt)) if temp!=1: arr.append((temp, 1)) if arr==[]: arr.append((n, 1)) return arr import math def pre_garner(amari, waru): for i in range(len(amari)): for j in range(i): g = math.gcd(waru[i], waru[j]) if (amari[i] - amari[j])%g!=0: return None, None new_waru = [1] * len(waru) dicts = {} num_dict = {} # 各素数を指数が最大のとこに割りふる for i, wa in enumerate(waru): for p,beki in factorization(wa): if p in dicts: # 保存されてるpの最大の指数より大きかったらその時のindexとp^bekiを保存 if dicts[p] < beki: dicts[p] = beki num_dict[p] = (i, pow(p,beki)) else: dicts[p] = beki num_dict[p] = (i, pow(p,beki)) for (i, num) in num_dict.values(): new_waru[i] *= num # 余りを更新する for i in range(len(amari)): amari[i] %= new_waru[i] return amari, new_waru def GANER_ALGORYTHM(amari, waru, MOD=10**9+7): waru.append(MOD) coeff = [1] * len(waru) constant = [0] * len(waru) for i in range(len(amari)): t = (((amari[i] - constant[i])% waru[i]) * pow(coeff[i], -1, waru[i])) % waru[i] for j in range(len(waru)): constant[j] = (constant[j] + t*coeff[j])%waru[j] coeff[j] = (coeff[j]*waru[i]) % waru[j] return constant def oi(): return int(input()) def os(): return input() def mi(): return list(map(int, input().split())) # import sys # input = sys.stdin.readline # import sys # sys.setrecursionlimit(10**8) # import pypyjit # pypyjit.set_param('max_unroll_recursion=-1') # input_count = 0 input_count = 0 N = oi() amari = [] wari = [] all_zero = True for _ in range(N): x,y = mi() wari.append(y) amari.append(x) if x != 0: all_zero = False if all_zero: amari, wari = pre_garner(amari, wari) out = 1 for w in wari: out = (out*w)%(10**9+7) print(out) else: amari, wari = pre_garner(amari, wari) if amari is None: print(-1) else: out = GANER_ALGORYTHM(amari, wari) print(out[-1])