結果

問題 No.2119 一般化百五減算
ユーザー ニックネームニックネーム
提出日時 2022-11-04 22:20:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 536 bytes
コンパイル時間 364 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 8,144 KB
最終ジャッジ日時 2023-09-26 00:48:40
合計ジャッジ時間 1,997 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,024 KB
testcase_01 AC 16 ms
7,968 KB
testcase_02 AC 16 ms
7,988 KB
testcase_03 AC 16 ms
7,940 KB
testcase_04 WA -
testcase_05 AC 16 ms
7,944 KB
testcase_06 AC 16 ms
8,072 KB
testcase_07 WA -
testcase_08 AC 16 ms
7,900 KB
testcase_09 AC 17 ms
7,940 KB
testcase_10 AC 16 ms
8,024 KB
testcase_11 WA -
testcase_12 AC 16 ms
8,068 KB
testcase_13 AC 17 ms
8,112 KB
testcase_14 AC 16 ms
7,956 KB
testcase_15 AC 16 ms
7,936 KB
testcase_16 AC 16 ms
7,940 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 16 ms
8,016 KB
testcase_20 WA -
testcase_21 AC 16 ms
7,960 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0