結果
問題 |
No.36 素数が嫌い!
|
ユーザー |
|
提出日時 | 2017-08-13 10:19:54 |
言語 | Nim (2.2.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 743 bytes |
コンパイル時間 | 2,902 ms |
コンパイル使用メモリ | 69,796 KB |
実行使用メモリ | 27,264 KB |
最終ジャッジ日時 | 2024-06-30 02:31:58 |
合計ジャッジ時間 | 4,631 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 17 WA * 9 |
コンパイルメッセージ
/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]
ソースコード
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 proc getIsPrime(n:int) : bool = # O(N/2) let primes = getPrimes(n.float.sqrt.int + 1) for p in primes: if n mod p == 0 and n != p: return false return true let N = get().parseInt() if N == 1 or getIsPrime(N): echo "NO" else: echo "YES"