結果

問題 No.187 中華風 (Hard)
ユーザー Yuki IwatakeYuki Iwatake
提出日時 2021-03-07 12:59:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 758 bytes
コンパイル時間 202 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-17 08:20:05
合計ジャッジ時間 1,718 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
10,880 KB
testcase_01 AC 35 ms
10,880 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 37 ms
10,880 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 38 ms
10,880 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 29 ms
10,752 KB
testcase_18 AC 33 ms
11,008 KB
testcase_19 AC 29 ms
10,752 KB
testcase_20 WA -
testcase_21 AC 27 ms
10,752 KB
testcase_22 WA -
testcase_23 AC 28 ms
10,752 KB
testcase_24 AC 28 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def CRT(BMlist):
    # Extended Euclidean Algorithm
    def extgcd(a, b):
        if b:
            d, y, x = extgcd(b, a % b)
            y -= (a // b)*x
            return d, x, y
        return a, 1, 0
    r = 0; M = 1
    for b,m in BMlist:
        d,p,q = extgcd(M,m)
        if (b-r)%d != 0:
            return 0,-1
        r += M*((b-r)//d*p%(m//d))
        M *= m//d
        r %= sml; M %= sml
    return r%sml,M%sml

import math
BMlist = []
ans = 1
sml = 10**9+7
N = int(input())
for i in range(N):
    x,y = map(int, input().split())
    BMlist.append((x,y))
    g = math.gcd(ans,y)
    ans = ((ans*y)//g)%sml
r,m = CRT(BMlist)
if r != 0:
    print(r)
elif m == -1:
    print(-1)
else:
    if ans != 1:
        print(ans)
    else:
        print(0)
0