結果

問題 No.106 素数が嫌い!2
ユーザー yukirinyukirin
提出日時 2016-02-25 16:19:16
言語 Go
(1.22.1)
結果
TLE  
実行時間 -
コード長 762 bytes
コンパイル時間 12,238 ms
コンパイル使用メモリ 239,348 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-19 06:07:29
合計ジャッジ時間 43,545 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,962 ms
6,812 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1,984 ms
5,376 KB
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 AC 124 ms
5,376 KB
testcase_09 AC 134 ms
5,376 KB
testcase_10 TLE -
testcase_11 AC 1,644 ms
6,940 KB
testcase_12 AC 4,883 ms
6,944 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"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()
	t := 0
	for i := 2; i <= n; i++ {
		ns := factor(int(i))
		m := make(map[int]struct{})

		for _, v := range ns {
			m[v] = struct{}{}
		}

		if len(m) >= k {
			t++
		}
	}
	fmt.Println(t)
}

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

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

func factor(n int) []int {
	if n <= 1 {
		return []int{n}
	}

	ps := make([]int, 0, 100)

	for i := int(2); i*i <= n; i++ {
		for n%i == 0 {
			n /= i
			ps = append(ps, i)
		}
	}
	if n > 1 {
		ps = append(ps, n)
	}
	return ps
}
0