結果

問題 No.106 素数が嫌い!2
ユーザー yukirinyukirin
提出日時 2016-02-25 16:26:11
言語 Go
(1.22.1)
結果
TLE  
実行時間 -
コード長 729 bytes
コンパイル時間 12,414 ms
コンパイル使用メモリ 235,512 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 06:08:49
合計ジャッジ時間 47,265 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,029 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2,031 ms
5,376 KB
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 AC 124 ms
5,376 KB
testcase_09 AC 135 ms
5,376 KB
testcase_10 TLE -
testcase_11 AC 1,699 ms
5,376 KB
testcase_12 TLE -
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 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))
		if len(ns) >= 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
			if len(ps) == 0 || i > ps[len(ps)-1] {
				ps = append(ps, i)
			}
		}
	}
	if n > 1 {
		ps = append(ps, n)
	}
	return ps
}
0