結果

問題 No.1644 Eight Digits
ユーザー 👑 obakyanobakyan
提出日時 2021-08-13 21:25:50
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 53 ms / 1,000 ms
コード長 823 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 6,684 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 16:38:26
合計ジャッジ時間 2,599 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
6,812 KB
testcase_01 AC 49 ms
6,940 KB
testcase_02 AC 50 ms
6,940 KB
testcase_03 AC 50 ms
6,940 KB
testcase_04 AC 50 ms
6,940 KB
testcase_05 AC 50 ms
6,944 KB
testcase_06 AC 50 ms
6,940 KB
testcase_07 AC 50 ms
6,940 KB
testcase_08 AC 53 ms
6,944 KB
testcase_09 AC 49 ms
6,940 KB
testcase_10 AC 49 ms
6,940 KB
testcase_11 AC 50 ms
6,944 KB
testcase_12 AC 50 ms
6,944 KB
testcase_13 AC 49 ms
6,940 KB
testcase_14 AC 49 ms
6,944 KB
testcase_15 AC 49 ms
6,944 KB
testcase_16 AC 50 ms
6,940 KB
testcase_17 AC 49 ms
6,940 KB
testcase_18 AC 49 ms
6,944 KB
testcase_19 AC 50 ms
6,940 KB
testcase_20 AC 49 ms
6,944 KB
testcase_21 AC 49 ms
6,940 KB
testcase_22 AC 49 ms
6,944 KB
testcase_23 AC 50 ms
6,940 KB
testcase_24 AC 50 ms
6,940 KB
testcase_25 AC 50 ms
6,944 KB
testcase_26 AC 49 ms
6,940 KB
testcase_27 AC 50 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mfl, mce = math.floor, math.ceil
local function getpattern(n, patall, idx)
  local used = {}
  local retary = {}
  local div = patall
  for i = 1, n do used[i] = false end
  for i = n, 1, -1 do
    div = mfl(div / i)
    local v_idx = mfl(idx / div)
    idx = idx % div
    local tmp_idx = 0
    for j = 1, n do
      if not used[j] then
        if tmp_idx == v_idx then
          table.insert(retary, j)
          used[j] = true
          break
        else
          tmp_idx = tmp_idx + 1
        end
      end
    end
  end
  return retary
end
local k = io.read("*n")
local c = 0
local all = 1
for i = 1, 8 do
  all = all * i
end
for i = 0, all - 1 do
  local p = getpattern(8, all, i)
  local v, m = 0, 1
  for j = 1, 8 do
    v = v + m * p[j]
    m = m * 10
  end
  if v % k == 0 then c = c + 1 end
end
print(c)
0