結果

問題 No.2119 一般化百五減算
ユーザー roarisroaris
提出日時 2022-11-04 23:00:46
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 665 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 87,228 KB
実行使用メモリ 87,668 KB
最終ジャッジ日時 2023-09-26 01:30:40
合計ジャッジ時間 6,392 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
75,916 KB
testcase_01 AC 97 ms
71,440 KB
testcase_02 AC 102 ms
71,540 KB
testcase_03 AC 97 ms
71,404 KB
testcase_04 AC 102 ms
71,404 KB
testcase_05 AC 100 ms
71,576 KB
testcase_06 AC 97 ms
71,672 KB
testcase_07 AC 93 ms
71,680 KB
testcase_08 AC 98 ms
71,628 KB
testcase_09 AC 95 ms
71,384 KB
testcase_10 AC 95 ms
71,580 KB
testcase_11 AC 97 ms
71,732 KB
testcase_12 AC 97 ms
71,552 KB
testcase_13 AC 96 ms
71,556 KB
testcase_14 AC 93 ms
71,340 KB
testcase_15 AC 97 ms
71,784 KB
testcase_16 AC 100 ms
71,700 KB
testcase_17 AC 100 ms
71,580 KB
testcase_18 AC 95 ms
71,568 KB
testcase_19 AC 93 ms
71,716 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

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

def crt(rs, ms):
    x = 0; d = 1
    for X, Y in zip(rs, ms):
        g, a, b = extgcd(d, Y)
        x, d = (Y*b*x + d*a*X) // g, d*(Y // g)
        x %= d
    return x, d

N = int(input())
M = int(input())
rs, ms = [], []

for _ in range(M):
    B, C = map(int, input().split())
    C %= B
    rs.append(C)
    ms.append(B)

x, d = crt(rs, ms)

for X, Y in zip(rs, ms):
    if x%Y!=X:
        print('NaN')
        exit(0)

if x>N:
    print('NaN')
else:
    print(x)
0