結果
| 問題 |
No.2016 Countdown Divisors
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2022-07-22 22:16:49 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,339 bytes |
| コンパイル時間 | 144 ms |
| コンパイル使用メモリ | 6,944 KB |
| 実行使用メモリ | 47,780 KB |
| 最終ジャッジ日時 | 2024-07-04 06:42:52 |
| 合計ジャッジ時間 | 3,825 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 1 |
| other | WA * 1 TLE * 1 -- * 17 |
ソースコード
local mce, mfl, msq, mmi, mma, mab = math.ceil, math.floor, math.sqrt, math.min, math.max, math.abs
local function getprimes(x)
local primes = {}
local allnums = {}
for i = 1, x do allnums[i] = true end
for i = 2, x do
if allnums[i] then
table.insert(primes, i)
local lim = mfl(x / i)
for j = 2, lim do
allnums[j * i] = false
end
end
end
return primes
end
local function getdivisorparts(x, primes)
local prime_num = #primes
local lim = mce(msq(x))
local primepos = 1
local dv = primes[primepos]
local ans = 1
while primepos <= prime_num and dv <= lim do
if x % dv == 0 then
local cnt = 1
x = mfl(x / dv)
while x % dv == 0 do
x = mfl(x / dv)
cnt = cnt + 1
end
ans = ans * (cnt + 1)
lim = mce(msq(x))
end
if primepos == prime_num then break end
primepos = primepos + 1
dv = primes[primepos]
end
if x ~= 1 then
ans = ans * 2
end
return ans
end
local primes = getprimes(100000)
local t = {}
t[1] = 1
t[2] = 2
local function solve(n)
if t[n] then return n end
local z = getdivisorparts(n, primes)
t[n] = n - z
if n == z then
t[n] = z
return z
end
return solve(n - z)
end
local q = io.read("*n")
for iq = 1, q do
local n = io.read("*n")
local z = solve(n)
print(z)
end