結果

問題 No.141 魔法少女コバ
ユーザー horiesiniti
提出日時 2018-03-31 18:22:09
言語 Ruby
(3.4.1)
結果
AC  
実行時間 96 ms / 5,000 ms
コード長 246 bytes
コンパイル時間 370 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-06-26 03:37:46
合計ジャッジ時間 11,679 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 93
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:29: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

m,n=gets.split.map{|e| e.to_i}
d=m.gcd(n)
m/=d
n/=d
ans=0
while m+n>2
	if m<n
		t=n
		n=m
		m=t
		ans+=1
	end
	if m==n
		break
	end
	if n==1
		ans+=(m-1)
		m=1
		break
	end
	
	t=m/n
	ans+=t
	m=m-t*n
end
if m==1 && n==1
	puts ans
else
	puts -1
end
0