結果

問題 No.1450 nahco314's First Problem
ユーザー 👑 obakyan
提出日時 2021-06-08 22:52:29
言語 Lua
(LuaJit 2.1.1734355927)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 662 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 5,376 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-08 14:29:31
合計ジャッジ時間 1,757 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

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 x = io.read()
x = lltonumber(x)

for i = -300, 300 do
  local v = x + i
  if v <= 1LL then v = 1LL end
  local c = 0
  local tv = v
  for j = 1, 60 do
    if tv % 2LL == 1LL then c = c + 1 end
    tv = tv / 2LL
  end
  local mul = 1LL
  local ret = 0LL
  tv = v
  for j = 1, 60 do
    if tv % 2LL ~= c % 2LL then
      ret = ret + mul
    end
    tv = tv / 2LL
    c = c / 2LL
    mul = mul * 2LL
  end
  if ret == x then
    local a = tostring(v):gsub("LL", "")
    print(a)
    os.exit()
  end
end
print(-1)
0