結果

問題 No.141 魔法少女コバ
コンテスト
ユーザー maguroguma
提出日時 2017-09-23 21:55:11
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
WA  
実行時間 -
コード長 508 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 597 ms
コンパイル使用メモリ 20,824 KB
実行使用メモリ 21,756 KB
最終ジャッジ日時 2026-05-09 17:42:47
合計ジャッジ時間 7,826 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1 WA * 2 TLE * 1 -- * 89
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# -*- coding: utf-8 -*-

import math

M,N = map(int, input().split())
gcd_mn = math.gcd(M, N)
M //= gcd_mn
N //= gcd_mn

ans = 0
# MとNが共に1,もしくは片方が負数となった時点でループを抜ける
while True:
    if (M==1 and N==1) or M<0 or N<0:
        break
    if M<N:
        temp = M
        M = N
        N = temp
        ans += 1
    else:
        # M<NとなるようにMをnN減じる
        n = M//N
        M -= (n-1)*N

if M==1 and N==1:
    print(ans)
else:
    print(-1)
0