結果

問題 No.1176 少ない質問
ユーザー 👑 obakyanobakyan
提出日時 2020-11-26 10:32:44
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 118 ms / 1,000 ms
コード長 736 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 5,332 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-01 03:15:58
合計ジャッジ時間 3,556 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
4,376 KB
testcase_01 AC 109 ms
4,376 KB
testcase_02 AC 115 ms
4,376 KB
testcase_03 AC 114 ms
4,380 KB
testcase_04 AC 112 ms
4,376 KB
testcase_05 AC 109 ms
4,380 KB
testcase_06 AC 112 ms
4,376 KB
testcase_07 AC 110 ms
4,380 KB
testcase_08 AC 106 ms
4,380 KB
testcase_09 AC 112 ms
4,376 KB
testcase_10 AC 103 ms
4,380 KB
testcase_11 AC 104 ms
4,376 KB
testcase_12 AC 108 ms
4,376 KB
testcase_13 AC 101 ms
4,380 KB
testcase_14 AC 109 ms
4,380 KB
testcase_15 AC 110 ms
4,376 KB
testcase_16 AC 112 ms
4,376 KB
testcase_17 AC 118 ms
4,376 KB
testcase_18 AC 109 ms
4,380 KB
testcase_19 AC 109 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local ffi = require("ffi")
local C = ffi.C
ffi.cdef[[
long long atoll(const char*);
]]

local function lltonumber(str)
  return C.atoll(str)
end

local a = io.read()
a = lltonumber(a)

-- find min n*m where a <= n^m
-- 2 <= a <= 10^18

local function llmin(x, y) return x < y and x or y end
-- m = 1
local ans = a
-- m = 2
local min, max = 0LL, 1000000007LL
while 1LL < max - min do
  local mid = (min + max) / 2LL
  if a <= mid * mid then
    max = mid
  else
    min = mid
  end
end
ans = llmin(ans, max * 2LL)
-- 3 <= m
for i = 2, 1000001 do
  local li = 1LL * i
  local ta = a - 1LL
  local m = 1
  while li <= ta do
    m = m + 1
    ta = ta / li
  end
  ans = llmin(ans, li * m)
end

ans = tostring(ans):gsub("LL", "")
print(ans)
0