結果
問題 | No.376 立方体のN等分 (2) |
ユーザー | 👑 obakyan |
提出日時 | 2019-05-09 08:51:19 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
AC
|
実行時間 | 2,824 ms / 5,000 ms |
コード長 | 2,943 bytes |
コンパイル時間 | 207 ms |
コンパイル使用メモリ | 6,944 KB |
実行使用メモリ | 142,484 KB |
最終ジャッジ日時 | 2024-07-02 00:45:16 |
合計ジャッジ時間 | 27,204 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 398 ms
76,512 KB |
testcase_03 | AC | 393 ms
76,608 KB |
testcase_04 | AC | 505 ms
142,140 KB |
testcase_05 | AC | 1 ms
6,944 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 13 ms
7,424 KB |
testcase_09 | AC | 66 ms
21,368 KB |
testcase_10 | AC | 261 ms
37,552 KB |
testcase_11 | AC | 205 ms
72,364 KB |
testcase_12 | AC | 276 ms
72,488 KB |
testcase_13 | AC | 275 ms
72,476 KB |
testcase_14 | AC | 308 ms
72,540 KB |
testcase_15 | AC | 342 ms
72,512 KB |
testcase_16 | AC | 2,438 ms
76,844 KB |
testcase_17 | AC | 383 ms
76,524 KB |
testcase_18 | AC | 446 ms
142,056 KB |
testcase_19 | AC | 458 ms
142,108 KB |
testcase_20 | AC | 468 ms
141,984 KB |
testcase_21 | AC | 2,635 ms
142,332 KB |
testcase_22 | AC | 483 ms
141,992 KB |
testcase_23 | AC | 2,692 ms
142,320 KB |
testcase_24 | AC | 2,369 ms
142,316 KB |
testcase_25 | AC | 502 ms
142,000 KB |
testcase_26 | AC | 2,824 ms
142,484 KB |
testcase_27 | AC | 504 ms
142,000 KB |
testcase_28 | AC | 507 ms
141,988 KB |
testcase_29 | AC | 507 ms
142,208 KB |
testcase_30 | AC | 507 ms
142,160 KB |
testcase_31 | AC | 503 ms
142,160 KB |
testcase_32 | AC | 507 ms
142,056 KB |
testcase_33 | AC | 508 ms
142,008 KB |
testcase_34 | AC | 505 ms
142,068 KB |
testcase_35 | AC | 505 ms
142,088 KB |
testcase_36 | AC | 503 ms
142,000 KB |
testcase_37 | AC | 504 ms
142,036 KB |
testcase_38 | AC | 506 ms
142,092 KB |
testcase_39 | AC | 506 ms
142,028 KB |
ソースコード
local n = io.read("*n") local mce, mfl, msq, mmi = math.ceil, math.floor, math.sqrt, math.min 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 tmp = {} local lim = mce(msq(x)) local primepos = 1 local dv = primes[primepos] while(primepos <= prime_num and dv <= lim) do if(x % dv == 0) then local asdf = {} asdf.p = dv asdf.cnt = 1 x = x / dv while(x % dv == 0) do x = x / dv asdf.cnt = asdf.cnt + 1 end table.insert(tmp, asdf) lim = mce(msq(x)) end if(primepos == prime_num) then break end primepos = primepos + 1 dv = primes[primepos] end if(x ~= 1) then local asdf = {} asdf.p, asdf.cnt = x, 1 table.insert(tmp, asdf) end return tmp end local function getdivisor(divisorparts, minlim) local t = {} local pat = 1 local len = #divisorparts local allpat = 1 for i = 1, len do allpat = allpat * (divisorparts[i].cnt + 1) end for t_i_pat = 0, allpat - 1 do local div = allpat local i_pat = t_i_pat local ret = 1 for i = 1, len do div = mfl(div / (divisorparts[i].cnt + 1)) local mul = mfl(i_pat / div) i_pat = i_pat % div for j = 1, mul do ret = ret * divisorparts[i].p end end if minlim == nil or minlim <= ret then table.insert(t, ret) end end table.sort(t) return t end local retmin, retmax = n - 1, n - 1 local primes = getprimes(mce(msq(n))) local divisorparts = getdivisorparts(n, primes) local divisor = getdivisor(divisorparts) local dmax = mce(n^(1/3)) for i = 1, #divisor do if(dmax < divisor[i]) then break end local divpart = getdivisorparts(divisor[i], primes) local remparts = {} local k = 1 for j = 1, #divpart do while(k <= #divisorparts) do local tmp = {} tmp.p = divisorparts[k].p if divpart[j].p == divisorparts[k].p then tmp.cnt = divisorparts[k].cnt - divpart[j].cnt table.insert(remparts, tmp) k = k + 1 break else tmp.cnt = divisorparts[k].cnt table.insert(remparts, tmp) k = k + 1 end end end while(k <= #divisorparts) do local tmp = {} tmp.p = divisorparts[k].p tmp.cnt = divisorparts[k].cnt table.insert(remparts, tmp) k = k + 1 end local rem = mfl(n / divisor[i]) local remdiv = getdivisor(remparts, divisor[i]) local remlim = mce(msq(rem)) for j = 1, #remdiv do if(remlim < remdiv[j]) then break end local last = mfl(rem / remdiv[j]) retmin = mmi(retmin, divisor[i] + remdiv[j] + last - 3) end end print(retmin .. " " .. retmax)