結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
64,028 KB
testcase_01 AC 55 ms
64,028 KB
testcase_02 AC 533 ms
76,680 KB
testcase_03 AC 524 ms
76,676 KB
testcase_04 AC 519 ms
76,428 KB
testcase_05 AC 519 ms
76,276 KB
testcase_06 AC 520 ms
76,404 KB
testcase_07 AC 521 ms
76,276 KB
testcase_08 AC 634 ms
73,468 KB
testcase_09 AC 639 ms
73,468 KB
testcase_10 AC 634 ms
73,468 KB
testcase_11 AC 520 ms
76,420 KB
testcase_12 AC 520 ms
76,276 KB
testcase_13 AC 452 ms
73,092 KB
testcase_14 AC 468 ms
73,244 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 40 ms
59,624 KB
testcase_18 AC 52 ms
63,772 KB
testcase_19 AC 39 ms
59,624 KB
testcase_20 AC 442 ms
76,708 KB
testcase_21 AC 40 ms
59,616 KB
testcase_22 AC 531 ms
76,428 KB
testcase_23 AC 38 ms
53,844 KB
testcase_24 AC 41 ms
59,616 KB
権限があれば一括ダウンロードができます

ソースコード

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):
    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 = []
for _ in range(N):
    x,y = mi()
    wari.append(y)
    amari.append(x)
amari, wari = pre_garner(amari, wari)
if amari is None:
    print(-1)
else:
    out = GANER_ALGORYTHM(amari, wari)
    print(out[-1])
0