結果

問題 No.407 鴨等素数間隔列の数え上げ
コンテスト
ユーザー むらため
提出日時 2019-01-23 20:28:51
言語 Nim
(2.2.8)
コンパイル:
nim --nimcache=~ --hints:off -o:a.out -d:release cpp _filename_
実行:
./a.out
結果
AC  
実行時間 44 ms / 1,000 ms
コード長 616 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,015 ms
コンパイル使用メモリ 68,348 KB
実行使用メモリ 10,060 KB
最終ジャッジ日時 2026-03-22 09:31:27
合計ジャッジ時間 3,018 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'sequtils' [UnusedImport]

ソースコード

diff #
raw source code

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
let n = scan()
let k = scan()
if k == 0 : quit "0",0
var isNotPrimes : array[1000_0010,bool]
var ans = 0
let primeMax = k div (n-1)
for i in 2..primeMax.float.sqrt.int:
  if isNotPrimes[i] : continue
  for j in countup(i*2,primeMax,i):
    isNotPrimes[j] = true

for i in 2..primeMax:
  if isNotPrimes[i] : continue
  let a = 1 + k - i * (n-1)
  if a <= 0 : break
  ans += a
echo ans
0