結果
問題 |
No.407 鴨等素数間隔列の数え上げ
|
ユーザー |
|
提出日時 | 2019-01-23 20:11:55 |
言語 | Nim (2.2.0) |
結果 |
AC
|
実行時間 | 102 ms / 1,000 ms |
コード長 | 803 bytes |
コンパイル時間 | 3,280 ms |
コンパイル使用メモリ | 62,084 KB |
実行使用メモリ | 27,420 KB |
最終ジャッジ日時 | 2024-07-01 10:38:36 |
合計ジャッジ時間 | 4,664 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 31 |
ソースコード
import sequtils,math proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .} proc scan(): int = while true: let k = getchar_unlocked() if k < '0': break result = 10 * result + k.ord - '0'.ord proc getIsPrimes(n:int) :seq[bool] = # [0...n] O(n loglog 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 = scan() let k = scan() if k == 0 : quit "0",0 let primes = getPrimes(k) var ans = 0 for p in primes: let a = 1 + k - p * (n-1) if a <= 0 : break ans += a echo ans