結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2,050 ms
5,376 KB
testcase_07 AC 2,046 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 55 ms
5,376 KB
testcase_10 AC 2,047 ms
5,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 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 += 2 {
		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