結果

問題 No.1312 Snake Eyes
ユーザー siman
提出日時 2020-12-10 07:20:28
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 466 bytes
コンパイル時間 521 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,544 KB
最終ジャッジ日時 2024-09-19 15:01:37
合計ジャッジ時間 16,709 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41 WA * 44
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i

def f(d, l, x)
  return false if x <= 1

  num = 0
  n = 1

  l.times do
    num += d * n
    n *= x
  end

  num
end

L = N.to_s(2).size
ans = Float::INFINITY

L.downto(1) do |l|
  1.upto(9) do |d|
    ng = 1
    ok = N

    while (ok - ng).abs >= 2
      x = (ok + ng) / 2

      if N <= f(d, l, x)
        ok = x
      else
        ng = x
      end
    end

    if d <= ok && f(d, l, ok) == N && ans > ok
      ans = ok
    end
  end
end

puts ans
0