結果
問題 | No.864 四方演算 |
ユーザー | 👑 obakyan |
提出日時 | 2019-08-17 00:44:41 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
AC
|
実行時間 | 30 ms / 1,000 ms |
コード長 | 2,120 bytes |
コンパイル時間 | 441 ms |
コンパイル使用メモリ | 5,336 KB |
実行使用メモリ | 12,120 KB |
最終ジャッジ日時 | 2023-10-26 02:48:17 |
合計ジャッジ時間 | 1,613 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 29 ms
11,832 KB |
testcase_02 | AC | 20 ms
11,600 KB |
testcase_03 | AC | 22 ms
11,324 KB |
testcase_04 | AC | 26 ms
12,120 KB |
testcase_05 | AC | 19 ms
11,324 KB |
testcase_06 | AC | 27 ms
11,840 KB |
testcase_07 | AC | 22 ms
11,324 KB |
testcase_08 | AC | 20 ms
11,324 KB |
testcase_09 | AC | 12 ms
7,228 KB |
testcase_10 | AC | 11 ms
7,100 KB |
testcase_11 | AC | 6 ms
4,876 KB |
testcase_12 | AC | 21 ms
11,324 KB |
testcase_13 | AC | 14 ms
7,228 KB |
testcase_14 | AC | 7 ms
5,052 KB |
testcase_15 | AC | 30 ms
11,840 KB |
testcase_16 | AC | 21 ms
11,600 KB |
testcase_17 | AC | 25 ms
12,120 KB |
testcase_18 | AC | 23 ms
11,584 KB |
testcase_19 | AC | 19 ms
11,600 KB |
testcase_20 | AC | 27 ms
11,840 KB |
testcase_21 | AC | 22 ms
11,584 KB |
testcase_22 | AC | 20 ms
11,600 KB |
testcase_23 | AC | 5 ms
4,348 KB |
testcase_24 | AC | 19 ms
11,600 KB |
testcase_25 | AC | 11 ms
7,100 KB |
testcase_26 | AC | 21 ms
11,584 KB |
testcase_27 | AC | 2 ms
4,348 KB |
testcase_28 | AC | 1 ms
4,348 KB |
testcase_29 | AC | 1 ms
4,348 KB |
ソースコード
local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max 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) local t = {} local pat = 1 local len = #divisorparts local allpat = 1 for i = 1, len do allpat = allpat * (1 + divisorparts[i].cnt) 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 table.insert(t, ret) end -- table.sort(t) return t end local n, k = io.read("*n", "*n") local primes = getprimes(mce(msq(k))) local dvp = getdivisorparts(k, primes) local dv = getdivisor(dvp) local ret = 0LL local function count(t) if t <= 1 then return 0 elseif t <= n + 1 then return t - 1 elseif t <= 2 * n then return 2 * n + 1 - t else return 0 end end for i = 1, #dv do local a_c = dv[i] local b_d = k / a_c ret = ret + count(a_c) * count(b_d) end local str = tostring(ret):gsub("LL", "") print(str)