結果
| 問題 | 
                            No.187 中華風 (Hard)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2021-05-08 09:45:46 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 905 bytes | 
| コンパイル時間 | 85 ms | 
| コンパイル使用メモリ | 12,544 KB | 
| 実行使用メモリ | 10,880 KB | 
| 最終ジャッジ日時 | 2024-09-16 07:34:44 | 
| 合計ジャッジ時間 | 1,704 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 3 WA * 20 RE * 2 | 
ソースコード
# -*- coding: UTF-8 -*-
def exgcd(a: int, b: int) -> (int, int, int):
    # 返回 (gcd(a,b), x, y) 满足 gcd(a,b)=ax+by
    x1, x2, x3, x4 = 1, 0, 0, 1
    while b != 0:
        q = a // b
        x1, x2, x3, x4, a, b = x3, x4, x1 - x3 * q, x2 - x4 * q, b, a - b * q
    return a, x1, x2
def gcrt2(a: int, m1: int, b: int, m2: int) -> (int, int):
    d, x, y = exgcd(m1, m2)
    bma = b - a
    if bma % d != 0:
        return -1, -1
    t, y = m2 // d, bma // d
    res = x * y % t
    if res < 0:
        res += t
    return res * m1 + a, m1 * t
if __name__ == '__main__':
    n = int(input())
    ans, m0 = 0, 1
    for _ in range(0, n):
        d, c = (int(i) for i in input().split(' '))
        ans, m0 = gcrt2(ans, m0, c, d)
        if ans == -1:
            break
    if ans == -1:
        print(-1)
    elif ans == 0:
        print(m0 % 1000000007)
    else:
        print(ans % 1000000007)