結果

問題 No.144 エラトステネスのざる
ユーザー fmhrfmhr
提出日時 2015-06-13 01:37:30
言語 Go
(1.22.1)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 725 bytes
コンパイル時間 12,264 ms
コンパイル使用メモリ 231,424 KB
実行使用メモリ 9,728 KB
最終ジャッジ日時 2024-04-19 02:25:01
合計ジャッジ時間 11,591 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 38 ms
9,728 KB
testcase_14 AC 74 ms
9,728 KB
testcase_15 AC 74 ms
9,728 KB
testcase_16 AC 72 ms
9,728 KB
testcase_17 AC 75 ms
9,728 KB
testcase_18 AC 77 ms
9,728 KB
testcase_19 AC 42 ms
9,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"math"
)

func main() {
	var N int
	var p float64
	fmt.Scan(&N, &p)
	var ans float64
	p = 1 - p
	d := divisorCounter(N)
	//fmt.Println(d)

	for i := 2; i<=N; i++ {
		if d[i]==0 {
			ans+=1
		}else {
			ans += math.Pow(p, float64(d[i]))
		}
	}

	fmt.Println(ans)

}

const MAX_N = 100000000
var isNotPrime [MAX_N+1]bool
func sieve(n int)[]int{
	prime := make([]int, 0)
	isNotPrime[0]=true
	isNotPrime[1]=true
	for i:=2; i<=n; i++{
		if !isNotPrime[i]{
			prime = append(prime,i)
			for j:=2*i; j<=n; j+=i{
				isNotPrime[j]=true
			}
		}
	}
	return prime
}

func divisorCounter(n int)[]int{
	d := make([]int, n+1)
	for i:=2;i<n+1;i++{
		for j := i*2; j<n+1; j += i{
			d[j]++
		}
	}
	return d
}
0