結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー aru aruaru aru
提出日時 2021-01-02 12:00:39
言語 Go
(1.22.1)
結果
AC  
実行時間 471 ms / 1,000 ms
コード長 1,936 bytes
コンパイル時間 16,256 ms
コンパイル使用メモリ 218,444 KB
実行使用メモリ 57,216 KB
最終ジャッジ日時 2024-04-20 06:41:21
合計ジャッジ時間 17,161 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 15 ms
7,040 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 436 ms
51,968 KB
testcase_06 AC 156 ms
30,336 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 17 ms
7,040 KB
testcase_20 AC 63 ms
18,560 KB
testcase_21 AC 20 ms
8,832 KB
testcase_22 AC 16 ms
7,808 KB
testcase_23 AC 36 ms
12,416 KB
testcase_24 AC 62 ms
18,560 KB
testcase_25 AC 132 ms
29,440 KB
testcase_26 AC 133 ms
29,440 KB
testcase_27 AC 11 ms
5,632 KB
testcase_28 AC 41 ms
13,312 KB
testcase_29 AC 129 ms
28,800 KB
testcase_30 AC 14 ms
6,528 KB
testcase_31 AC 93 ms
23,808 KB
testcase_32 AC 140 ms
29,056 KB
testcase_33 AC 456 ms
57,216 KB
testcase_34 AC 471 ms
57,216 KB
testcase_35 AC 380 ms
50,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func getI() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getI()
	}
	return ret
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

// min for n entry
func nmin(a ...int) int {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int) int {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func prime(n int) []int {
	a := make([]int, n+1)
	for i := 2; i*i <= n; i++ {
		for j := i * 2; j <= n; j += i {
			a[j] = 1
		}
	}
	ret := make([]int, 0)
	for i := 2; i <= n; i++ {
		if a[i] == 0 {
			ret = append(ret, i)
		}
	}
	return ret
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	N, L := getI(), getI()
	p := prime((L + 1) / 2)
	cnt := 0
	for _, e := range p {
		v := e * (N - 1)
		if v <= L {
			cnt += L - v + 1
		}
	}
	out(cnt)
}
0