結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
11,008 KB
testcase_01 AC 31 ms
11,008 KB
testcase_02 AC 44 ms
11,008 KB
testcase_03 AC 44 ms
11,136 KB
testcase_04 AC 74 ms
11,136 KB
testcase_05 AC 75 ms
11,136 KB
testcase_06 AC 74 ms
11,136 KB
testcase_07 AC 72 ms
11,008 KB
testcase_08 AC 74 ms
11,136 KB
testcase_09 AC 75 ms
11,136 KB
testcase_10 AC 77 ms
11,136 KB
testcase_11 AC 73 ms
11,136 KB
testcase_12 AC 72 ms
11,264 KB
testcase_13 AC 34 ms
10,880 KB
testcase_14 AC 33 ms
10,880 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 28 ms
10,752 KB
testcase_18 AC 33 ms
11,008 KB
testcase_19 AC 28 ms
10,752 KB
testcase_20 AC 61 ms
11,008 KB
testcase_21 AC 28 ms
10,880 KB
testcase_22 AC 69 ms
11,136 KB
testcase_23 WA -
testcase_24 AC 27 ms
10,880 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
    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:
    print(ans)
0