結果

問題 No.187 中華風 (Hard)
ユーザー akasia_midoriakasia_midori
提出日時 2023-11-23 01:37:02
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,165 bytes
コンパイル時間 205 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 76,560 KB
最終ジャッジ日時 2023-11-23 01:37:13
合計ジャッジ時間 10,906 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 428 ms
76,556 KB
testcase_01 AC 425 ms
76,432 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 39 ms
59,624 KB
testcase_18 AC 346 ms
74,516 KB
testcase_19 AC 38 ms
59,624 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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):
    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 = []
for _ in range(N):
    x,y = mi()
    wari.append(y)
    amari.append(x)
amari, wari = pre_garner(amari, wari)
out = GANER_ALGORYTHM(amari, wari)
flg = True
output = out[-1]
for a, w in zip(amari,wari[:-1]):
    if output%w != a:
        output = -1
        break
print(output)
0