結果

問題 No.144 エラトステネスのざる
ユーザー fmhrfmhr
提出日時 2015-06-13 01:32:03
言語 Go
(1.22.1)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 1,032 bytes
コンパイル時間 10,271 ms
コンパイル使用メモリ 231,828 KB
実行使用メモリ 16,304 KB
最終ジャッジ日時 2024-04-19 02:24:14
合計ジャッジ時間 11,576 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 34 ms
11,868 KB
testcase_14 AC 74 ms
11,868 KB
testcase_15 AC 72 ms
11,864 KB
testcase_16 AC 74 ms
11,864 KB
testcase_17 AC 73 ms
11,864 KB
testcase_18 AC 72 ms
11,864 KB
testcase_19 AC 39 ms
16,304 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)
	if p == 0{
		ans = float64(len(sieve(N)))
	}else if p == 1{
		ans = float64(N-1)
	}else {
		for i := 2; i<=N; i++ {
			div := d[i]
			if div==0 {
				ans+=1
			}else {
				ans += math.Pow(p, float64(div))
			}
			//fmt.Println(ans)
		}
	}
	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
}

func divisor(n int)[]int{
	res := make([]int, 0)
	for i:=1;i*i<=n;i++{
		if n%i==0{
			res = append(res,i)
			if i!=n/i{
				res = append(res,n/i)
			}
		}
	}
	return res
}
0