結果
| 問題 | 
                            No.2119 一般化百五減算
                             | 
                    
| コンテスト | |
| ユーザー | 
                             ニックネーム
                         | 
                    
| 提出日時 | 2022-11-04 22:20:21 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 536 bytes | 
| コンパイル時間 | 187 ms | 
| コンパイル使用メモリ | 12,416 KB | 
| 実行使用メモリ | 10,880 KB | 
| 最終ジャッジ日時 | 2024-07-18 20:13:51 | 
| 合計ジャッジ時間 | 1,813 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 16 WA * 9 | 
ソースコード
def extend_euclidean_algorithm(a, b):
    if b == 0: return 1, 0
    y, x = extend_euclidean_algorithm(b, a%b)
    y -= (a//b)*x
    return x, y
def chinese_remainder_theorem(s, p, t, q):
    d = gcd(p, q)
    if (s-t)%d: return -1, -1
    x, y = extend_euclidean_algorithm(p, q)
    return (s*q*y+t*p*x)//d, p*q//d
from math import gcd
n = int(input())
c, b = 0, 1
for _ in range(int(input())):
    bi, ci = map(int, input().split())
    c, b = chinese_remainder_theorem(c, b, ci, bi)
    if c == -1 or c > n: c = "NaN"; break
print(c)
            
            
            
        
            
ニックネーム