結果
| 問題 | 
                            No.187 中華風 (Hard)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Chihaya_chan
                         | 
                    
| 提出日時 | 2020-08-10 21:50:48 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                RE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,414 bytes | 
| コンパイル時間 | 289 ms | 
| コンパイル使用メモリ | 12,800 KB | 
| 実行使用メモリ | 11,264 KB | 
| 最終ジャッジ日時 | 2024-10-08 16:47:06 | 
| 合計ジャッジ時間 | 10,443 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 RE * 2 | 
ソースコード
#  中華風(easy)
import math
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0
# すなわちax==1(mod m)なる自然数xを返してくれる関数 動作時間:logM
def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        return False
    else:
        return x % m
def modular_numbers(pair1, pair2):
    x1, y1 = pair1
    x2, y2 = pair2
    g = math.gcd(y1, y2)
    if (x2-x1) % g != 0:
        return (float("inf"), float("inf"))
    else:
        K = (x2-x1)//g
        y1, y2 = y1//g, y2//g
        t = -K*modinv(y2, y1)
        m = x2+t*g*y2
        return (m % (g*y1*y2), g*y1*y2)
mod = 10**9 + 7
def main():
    N = int(input())
    que = [tuple(map(int, input().split())) for i in range(N)]
    base = modular_numbers(que[0], que[1])
    if base[0] == float("inf"):
        print(-1)
        return
    for i in range(2, N):
        base = modular_numbers(base, que[i])
        if base[0] == float("inf"):
            print(-1)
            return
        else:
            continue
    if base[0] == float("inf"):
        print(-1)
        return
    else:
        if base[0] > 0:
            print(base[0] % mod)
            return
        else:
            print(base[1] % mod)
            return
if __name__ == "__main__":
    main()
            
            
            
        
            
Chihaya_chan