結果

問題 No.25 有限小数
ユーザー fine
提出日時 2017-01-09 18:44:22
言語 Ruby
(3.4.1)
結果
AC  
実行時間 92 ms / 5,000 ms
コード長 457 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-12-18 00:19:02
合計ジャッジ時間 4,219 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:16: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

n, m = $<.map(&:to_i)
g = n.gcd(m)
n /= g
m /= g
if m != 1
    cnt = [0,0]
    while m % 2 == 0
        cnt[0] += 1
        m /= 2
    end
    while m % 5 == 0
        cnt[1] += 1
        m /= 5
    end
    if m != 1
        p -1
        exit
    end
    if cnt[0] > cnt[1]
        n *= 5 ** (cnt[0] - cnt[1])
    else 
        n *= 2 ** (cnt[1] - cnt[0])
    end
end
s = n.to_s.reverse
s.size.times do |i|
    next if s[i] == ?0
    puts s[i]
    break
end
0