結果

問題 No.25 有限小数
ユーザー ciel
提出日時 2014-11-28 18:20:05
言語 Ruby
(3.4.1)
結果
AC  
実行時間 160 ms / 5,000 ms
コード長 372 bytes
コンパイル時間 83 ms
コンパイル使用メモリ 7,296 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-12-26 02:49:09
合計ジャッジ時間 3,884 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
ruby: warning: shebang line ending with \r may cause problems
Main.rb:20: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
require 'rational'
n=gets.to_i
m=gets.to_i
g=n.gcd(m)
n/=g
m/=g
n/=10 while n%10==0
m/=10 while m%10==0
div=Hash.new(0)
while m%2==0
	m/=2
	div[2]+=1
end
while m%5==0
	m/=5
	div[5]+=1
end
if m!=1
	p -1
	exit
end
n%=10
div[2].times{|i|
	n*=5
	n = n%10==0 ? n/10 : n%10
}
div[5].times{|i|
	n*=2
	n = n%10==0 ? n/10 : n%10
}
p n
0