結果

問題 No.2119 一般化百五減算
ユーザー roarisroaris
提出日時 2022-11-04 23:03:32
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 712 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 87,060 KB
実行使用メモリ 86,036 KB
最終ジャッジ日時 2023-09-26 01:33:42
合計ジャッジ時間 4,449 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,712 KB
testcase_01 AC 92 ms
71,428 KB
testcase_02 AC 90 ms
71,508 KB
testcase_03 AC 94 ms
71,580 KB
testcase_04 AC 100 ms
71,536 KB
testcase_05 AC 95 ms
71,548 KB
testcase_06 AC 97 ms
71,548 KB
testcase_07 AC 95 ms
71,632 KB
testcase_08 AC 91 ms
71,408 KB
testcase_09 AC 92 ms
71,432 KB
testcase_10 AC 90 ms
71,640 KB
testcase_11 AC 90 ms
71,612 KB
testcase_12 AC 92 ms
71,580 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 92 ms
71,500 KB
testcase_20 WA -
testcase_21 AC 121 ms
82,032 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

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
        if d>N:
            exit(print('NaN'))
    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