結果
問題 | No.1312 Snake Eyes |
ユーザー | 👑 obakyan |
提出日時 | 2022-01-09 23:38:00 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
AC
|
実行時間 | 42 ms / 2,000 ms |
コード長 | 2,365 bytes |
コンパイル時間 | 189 ms |
コンパイル使用メモリ | 6,944 KB |
実行使用メモリ | 12,024 KB |
最終ジャッジ日時 | 2024-11-14 10:36:35 |
合計ジャッジ時間 | 5,167 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
11,676 KB |
testcase_01 | AC | 27 ms
11,804 KB |
testcase_02 | AC | 28 ms
11,772 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | AC | 1 ms
6,816 KB |
testcase_05 | AC | 28 ms
11,804 KB |
testcase_06 | AC | 28 ms
11,836 KB |
testcase_07 | AC | 29 ms
11,708 KB |
testcase_08 | AC | 28 ms
11,976 KB |
testcase_09 | AC | 28 ms
11,816 KB |
testcase_10 | AC | 28 ms
11,840 KB |
testcase_11 | AC | 27 ms
11,704 KB |
testcase_12 | AC | 29 ms
11,864 KB |
testcase_13 | AC | 28 ms
11,872 KB |
testcase_14 | AC | 28 ms
11,848 KB |
testcase_15 | AC | 31 ms
11,868 KB |
testcase_16 | AC | 28 ms
11,768 KB |
testcase_17 | AC | 28 ms
11,804 KB |
testcase_18 | AC | 29 ms
11,856 KB |
testcase_19 | AC | 28 ms
11,820 KB |
testcase_20 | AC | 28 ms
11,824 KB |
testcase_21 | AC | 27 ms
11,872 KB |
testcase_22 | AC | 27 ms
11,852 KB |
testcase_23 | AC | 28 ms
11,928 KB |
testcase_24 | AC | 28 ms
11,824 KB |
testcase_25 | AC | 28 ms
11,740 KB |
testcase_26 | AC | 28 ms
11,924 KB |
testcase_27 | AC | 29 ms
11,804 KB |
testcase_28 | AC | 27 ms
11,708 KB |
testcase_29 | AC | 27 ms
11,804 KB |
testcase_30 | AC | 28 ms
11,864 KB |
testcase_31 | AC | 28 ms
11,916 KB |
testcase_32 | AC | 29 ms
11,824 KB |
testcase_33 | AC | 28 ms
11,804 KB |
testcase_34 | AC | 28 ms
11,848 KB |
testcase_35 | AC | 29 ms
11,812 KB |
testcase_36 | AC | 28 ms
11,816 KB |
testcase_37 | AC | 28 ms
11,872 KB |
testcase_38 | AC | 28 ms
11,908 KB |
testcase_39 | AC | 35 ms
11,916 KB |
testcase_40 | AC | 30 ms
11,908 KB |
testcase_41 | AC | 36 ms
11,828 KB |
testcase_42 | AC | 35 ms
11,808 KB |
testcase_43 | AC | 35 ms
11,920 KB |
testcase_44 | AC | 35 ms
11,884 KB |
testcase_45 | AC | 29 ms
11,880 KB |
testcase_46 | AC | 35 ms
11,704 KB |
testcase_47 | AC | 36 ms
11,860 KB |
testcase_48 | AC | 37 ms
11,856 KB |
testcase_49 | AC | 37 ms
11,840 KB |
testcase_50 | AC | 36 ms
11,876 KB |
testcase_51 | AC | 36 ms
12,024 KB |
testcase_52 | AC | 38 ms
11,816 KB |
testcase_53 | AC | 37 ms
11,872 KB |
testcase_54 | AC | 39 ms
11,812 KB |
testcase_55 | AC | 37 ms
11,876 KB |
testcase_56 | AC | 34 ms
11,888 KB |
testcase_57 | AC | 36 ms
11,808 KB |
testcase_58 | AC | 37 ms
11,860 KB |
testcase_59 | AC | 31 ms
11,772 KB |
testcase_60 | AC | 36 ms
11,880 KB |
testcase_61 | AC | 37 ms
11,812 KB |
testcase_62 | AC | 32 ms
11,808 KB |
testcase_63 | AC | 28 ms
11,852 KB |
testcase_64 | AC | 28 ms
11,804 KB |
testcase_65 | AC | 29 ms
11,824 KB |
testcase_66 | AC | 28 ms
11,860 KB |
testcase_67 | AC | 28 ms
11,704 KB |
testcase_68 | AC | 27 ms
11,708 KB |
testcase_69 | AC | 27 ms
11,828 KB |
testcase_70 | AC | 28 ms
11,708 KB |
testcase_71 | AC | 28 ms
11,740 KB |
testcase_72 | AC | 28 ms
11,804 KB |
testcase_73 | AC | 28 ms
11,868 KB |
testcase_74 | AC | 30 ms
11,812 KB |
testcase_75 | AC | 28 ms
11,824 KB |
testcase_76 | AC | 42 ms
11,936 KB |
testcase_77 | AC | 38 ms
11,864 KB |
testcase_78 | AC | 38 ms
11,876 KB |
testcase_79 | AC | 28 ms
11,816 KB |
testcase_80 | AC | 38 ms
11,700 KB |
testcase_81 | AC | 36 ms
11,740 KB |
testcase_82 | AC | 29 ms
11,832 KB |
testcase_83 | AC | 37 ms
11,736 KB |
testcase_84 | AC | 38 ms
11,844 KB |
testcase_85 | AC | 28 ms
11,808 KB |
testcase_86 | AC | 28 ms
11,840 KB |
testcase_87 | AC | 37 ms
11,704 KB |
ソースコード
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 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 t = {} t.p = dv t.cnt = 1 x = mfl(x / dv) while x % dv == 0 do x = mfl(x / dv) t.cnt = t.cnt + 1 end table.insert(tmp, t) lim = mce(msq(x)) end if primepos == prime_num then break end primepos = primepos + 1 dv = primes[primepos] end if x ~= 1 then local t = {} t.p, t.cnt = x, 1 table.insert(tmp, t) end return tmp end local function getdivisorCore(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 function getdivisor(x, primes) local dvp = getdivisorparts(x, primes) return getdivisorCore(dvp) end local n = io.read("*n") if n == 1 then print(2) os.exit() end if n == 2 then print(3) os.exit() end local lim = 1000 * 1000 local primes = getprimes(lim) local dv = getdivisor(n, primes) local cand = 0 for i = #dv, 1, -1 do local a = dv[i] local b = mfl(n / a) if a < b - 1 then cand = b - 1 break end end for i = 2, lim do local v = i + 1 local found = false while v <= n do if n % v == 0 then local w = mfl(n / v) if w < i then cand = mmi(cand, i) found = true break end end v = v * i + 1 end if found then break end end print(cand)