結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー fmhrfmhr
提出日時 2016-08-05 23:18:16
言語 Go
(1.21.3)
結果
AC  
実行時間 84 ms / 1,000 ms
コード長 611 bytes
コンパイル時間 14,618 ms
コンパイル使用メモリ 208,220 KB
実行使用メモリ 33,068 KB
最終ジャッジ日時 2023-08-22 04:14:59
合計ジャッジ時間 16,955 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,356 KB
testcase_02 AC 1 ms
4,360 KB
testcase_03 AC 7 ms
7,704 KB
testcase_04 AC 1 ms
4,356 KB
testcase_05 AC 79 ms
32,888 KB
testcase_06 AC 42 ms
18,492 KB
testcase_07 AC 2 ms
4,356 KB
testcase_08 AC 1 ms
4,356 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 1 ms
4,360 KB
testcase_12 AC 2 ms
4,356 KB
testcase_13 AC 1 ms
4,356 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 1 ms
4,356 KB
testcase_17 AC 1 ms
4,352 KB
testcase_18 AC 2 ms
4,360 KB
testcase_19 AC 7 ms
7,848 KB
testcase_20 AC 25 ms
12,220 KB
testcase_21 AC 10 ms
7,860 KB
testcase_22 AC 8 ms
7,848 KB
testcase_23 AC 15 ms
9,936 KB
testcase_24 AC 24 ms
12,220 KB
testcase_25 AC 43 ms
18,488 KB
testcase_26 AC 43 ms
18,500 KB
testcase_27 AC 6 ms
7,696 KB
testcase_28 AC 19 ms
9,944 KB
testcase_29 AC 40 ms
18,404 KB
testcase_30 AC 6 ms
5,644 KB
testcase_31 AC 33 ms
14,368 KB
testcase_32 AC 40 ms
18,360 KB
testcase_33 AC 84 ms
32,840 KB
testcase_34 AC 83 ms
33,068 KB
testcase_35 AC 75 ms
33,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, L int
	fmt.Scan(&N, &L)
	prime := Sieve(L)
	sort.Ints(prime)
	ans := 0
	for _, p := range prime {
		if (N-1)*p <= L {
			//fmt.Println(p, L - (N - 1) * p + 1)
			ans += L - (N - 1) * p + 1
		}
	}
	fmt.Println(ans)
}

func Sieve(n int) []int {
	isNotPrime := make([]bool, n+1)
	primeList := make([]int, 0)
	isNotPrime[0] = true
	isNotPrime[1] = true
	for i := 2; i <= n; i++ {
		if !isNotPrime[i] {
			// 素数の場合
			primeList = append(primeList, i)
			for j := 2 * i; j <= n; j += i {
				isNotPrime[j] = true
			}
		}
	}
	return primeList
}
0