結果

問題 No.187 中華風 (Hard)
ユーザー 古寺いろは
提出日時 2015-04-20 00:12:05
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 160 ms / 3,000 ms
コード長 687 bytes
コンパイル時間 121 ms
コンパイル使用メモリ 77,056 KB
実行使用メモリ 78,592 KB
最終ジャッジ日時 2024-07-04 19:04:39
合計ジャッジ時間 4,012 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

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:
N = N - 1
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
if ans == 0:
ans = add
if ans >= 0:
ans = ans % 1000000007
print ans
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1