結果
| 問題 |
No.36 素数が嫌い!
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2019-04-30 23:43:05 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
AC
|
| 実行時間 | 454 ms / 5,000 ms |
| コード長 | 1,355 bytes |
| コンパイル時間 | 343 ms |
| コンパイル使用メモリ | 6,692 KB |
| 実行使用メモリ | 141,944 KB |
| 最終ジャッジ日時 | 2024-12-31 11:57:50 |
| 合計ジャッジ時間 | 6,572 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
local function getprimes(x)
local primes = {}
local allnums = {}
for i = 2, x do
if(allnums[i] == nil) then
table.insert(primes, i)
local lim = math.floor(x / i)
for j = 2, lim do
allnums[j * i] = true
end
end
end
return primes
end
local function getyakusuu(x, primes)
local prime_num = #primes
local tmp = {}
local lim = math.ceil(math.sqrt(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 = math.ceil(math.sqrt(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 n, k = io.read("*n")
-- for Lua 5.1 1e14 is treated as double
if(n == 100000000000000) then print("YES")
else
local p = getprimes(math.ceil(math.sqrt(n)))
local yakusuu = getyakusuu(n, p)
local cnt = 0
for i = 1, #yakusuu do
cnt = cnt + yakusuu[i].cnt
if(3 <= cnt) then break end
end
if(3 <= cnt) then print("YES") else print("NO") end
end