結果

問題 No.144 エラトステネスのざる
ユーザー fmhrfmhr
提出日時 2015-06-12 22:08:28
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 881 bytes
コンパイル時間 12,809 ms
コンパイル使用メモリ 229,576 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-04-19 02:21:19
合計ジャッジ時間 17,282 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

import (
	"fmt"
	"math"
)

func main() {
	var N int
	var p float64
	fmt.Scan(&N, &p)
	var ans float64
	if p == 0{
		ans = float64(len(sieve(N)))
	}else if p == 1{
		ans = float64(N-1)
	}else {
		for i := 2; i<=N; i++ {
			fmt.Println(i, divisor(i))
			if len(divisor(i))<2 {
				ans+=1
			}else {
				ans += math.Pow(p, float64(len(divisor(i))-2))
			}
			//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 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