結果

問題 No.106 素数が嫌い!2
ユーザー yukirinyukirin
提出日時 2016-02-25 17:37:39
言語 Go
(1.22.1)
結果
RE  
実行時間 -
コード長 1,007 bytes
コンパイル時間 11,298 ms
コンパイル使用メモリ 237,472 KB
実行使用メモリ 24,032 KB
最終ジャッジ日時 2024-04-19 06:11:29
合計ジャッジ時間 12,274 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
13,644 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 15 ms
13,644 KB
testcase_05 AC 36 ms
24,028 KB
testcase_06 AC 36 ms
24,032 KB
testcase_07 AC 37 ms
24,032 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 3 ms
6,944 KB
testcase_10 AC 35 ms
24,032 KB
testcase_11 AC 14 ms
13,644 KB
testcase_12 AC 33 ms
24,028 KB
testcase_13 RE -
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func main() {
	sc.Split(bufio.ScanWords)
	n, k := nextInt(), nextInt()
	ps, ns := eratosthenes(n), make([]int, n+1)

	for _, v := range ps {
		for i := v; i <= n; i += v {
			ns[i]++
		}
	}

	t := 0
	for _, v := range ns {
		if v >= k {
			t++
		}
	}
	fmt.Println(t)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextLine())
	return i
}

func eratosthenes(n int) []int {
	if n < 2 {
		return []int{}
	}

	r := int(math.Floor(math.Sqrt(float64(n))))
	list := make([]bool, n+1)
	list[0], list[1] = true, true

	for i := 2; i <= r; i++ {
		if !list[i] {
			for j := i * i; j <= n; j += i {
				list[j] = true
			}
		}
	}

	l := n / int(math.Floor(math.Log(float64(n))))
	primes := make([]int, 0, l)
	for i, v := range list {
		if v {
			continue
		}
		primes = append(primes, i)
	}

	return primes
}
0