結果
問題 | No.2119 一般化百五減算 |
ユーザー | roaris |
提出日時 | 2022-11-04 22:43:44 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 840 bytes |
コンパイル時間 | 284 ms |
コンパイル使用メモリ | 87,308 KB |
実行使用メモリ | 78,812 KB |
最終ジャッジ日時 | 2023-09-26 01:13:44 |
合計ジャッジ時間 | 6,129 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 87 ms
78,812 KB |
testcase_01 | AC | 87 ms
71,652 KB |
testcase_02 | AC | 88 ms
71,812 KB |
testcase_03 | AC | 84 ms
71,708 KB |
testcase_04 | AC | 86 ms
71,872 KB |
testcase_05 | AC | 85 ms
71,872 KB |
testcase_06 | AC | 86 ms
71,668 KB |
testcase_07 | AC | 87 ms
72,044 KB |
testcase_08 | AC | 86 ms
71,780 KB |
testcase_09 | AC | 87 ms
71,736 KB |
testcase_10 | AC | 86 ms
71,472 KB |
testcase_11 | AC | 86 ms
71,620 KB |
testcase_12 | AC | 84 ms
71,812 KB |
testcase_13 | AC | 85 ms
71,704 KB |
testcase_14 | AC | 87 ms
71,868 KB |
testcase_15 | AC | 85 ms
71,624 KB |
testcase_16 | AC | 83 ms
71,708 KB |
testcase_17 | AC | 85 ms
71,452 KB |
testcase_18 | AC | 87 ms
71,636 KB |
testcase_19 | AC | 85 ms
71,696 KB |
testcase_20 | TLE | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
ソースコード
import sys input = sys.stdin.readline from collections import * from math import gcd def extGCD(a, b): #ax+by=gcd(a,b)となる(x,y)を1つ求める if b==0: return 1, 0 s, t = extGCD(b, a%b) return t, s-a//b*t def crt(rs, ms): #x≡rs[0](mod ms[0]),...となるxについてx≡r(mod lcm(ms))となるrを求める r, m = 0, 1 for i in range(len(rs)): p, q = extGCD(m, ms[i]) g = gcd(m, ms[i]) if (rs[i]-r)%g!=0: return -1 t = (rs[i]-r)//g*p%(ms[i]//g) r += m*t m *= ms[i]//g return r%m 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 = crt(rs, ms) if x==-1 or x>N: print('NaN') else: print(x)