結果

問題 No.36 素数が嫌い!
ユーザー むらため
提出日時 2017-08-13 10:31:13
言語 Nim
(2.2.0)
結果
AC  
実行時間 100 ms / 5,000 ms
コード長 790 bytes
コンパイル時間 3,235 ms
コンパイル使用メモリ 68,224 KB
実行使用メモリ 27,264 KB
最終ジャッジ日時 2024-06-30 02:31:52
合計ジャッジ時間 5,115 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 50) Warning: Use the new 'sugar' module instead; future is deprecated [Deprecated]
/home/judge/data/code/Main.nim(1, 57) Warning: imported and not used: 'macros' [UnusedImport]
/home/judge/data/code/Main.nim(1, 50) Warning: imported and not used: 'future' [UnusedImport]
/home/judge/data/code/Main.nim(1, 26) Warning: imported and not used: 'strscans' [UnusedImport]
/home/judge/data/code/Main.nim(1, 35) Warning: imported and not used: 'algorithm' [UnusedImport]

ソースコード

diff #

import sequtils,strutils,strscans,algorithm,math,future,macros
template get*():string = stdin.readLine()

proc getIsPrimes(n:int) :seq[bool] = # [0...n]
  result = newSeqWith(n+1,true)
  result[0] = false
  result[1] = false
  for i in 2..n.float.sqrt.int :
    if not result[i]: continue
    for j in countup(i*2,n,i):
      result[j] = false

proc getPrimes(n:int):seq[int] = # [2,3,5,...n]
  let isPrimes = getIsPrimes(n)
  result = @[]
  for i,p in isPrimes:
    if p : result &= i

let
  N = get().parseInt()
  primes = getPrimes(N.float.sqrt.int + 1)
if N == 1 :
  echo "NO"
  quit()
for p1 in primes:
  if N mod p1 != 0: continue
  let factor = N div p1
  for p2 in primes:
    if factor mod p2 != 0: continue
    if factor == p2 : echo "NO"
    else: echo "YES"
    quit()
echo "NO"
0