結果

問題 No.187 中華風 (Hard)
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-19 23:58:56
言語 Python2
(2.7.18)
結果
RE  
実行時間 -
コード長 606 bytes
コンパイル時間 481 ms
コンパイル使用メモリ 6,672 KB
実行使用メモリ 6,180 KB
最終ジャッジ日時 2023-09-18 02:08:06
合計ジャッジ時間 2,265 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,848 KB
testcase_01 AC 12 ms
5,876 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 12 ms
5,844 KB
testcase_18 AC 11 ms
6,024 KB
testcase_19 AC 12 ms
5,964 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

def extgcd(a, b):
    if b == 0:
        return (a, 1, 0)
    (g, y, x) = extgcd(b, a % b)
    return (g, x, y - (a // b) * x)



N = int(raw_input()) - 1
ans, add = map(int,raw_input().strip().split());
if ans == 0:
    ans = ans + add

while N > 0:
    X, Y = map(int,raw_input().strip().split())
    g, a, b = extgcd(add, Y)
    now = ans % Y
    need = X - now
    if need < 0:
        need = need + Y
    if need % g != 0:
        ans = -1;
        break
    need = need / g
    ans = ans + (add * a) * need
    add = add * Y / g
    ans = ans % add
    if ans < 0:
        ans = ans + add

print(ans)
0