結果

問題 No.144 エラトステネスのざる
ユーザー koyumeishikoyumeishi
提出日時 2015-02-06 00:11:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 523 bytes
コンパイル時間 535 ms
コンパイル使用メモリ 76,116 KB
実行使用メモリ 15,332 KB
最終ジャッジ日時 2023-09-05 13:23:10
合計ジャッジ時間 2,000 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 61 ms
15,328 KB
testcase_14 AC 78 ms
15,320 KB
testcase_15 AC 86 ms
15,048 KB
testcase_16 AC 83 ms
15,296 KB
testcase_17 AC 83 ms
15,284 KB
testcase_18 AC 84 ms
15,332 KB
testcase_19 AC 55 ms
14,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;

int main(){
	int N;
	cin >> N;

	double p;
	cin >> p;

	vector<double> v(N+1, 1.0);
	v[0] = v[1] = 0.0;

	vector<int> cnt(N+1, 0);

	for(int i=2; i<=N/2; i++){
		for(int j=2*i; j<=N; j+=i){
			cnt[j]++;
		}
	}

	double ans = 0;
	for(int i=2; i<=N; i++){
		ans += pow(1.0-p, cnt[i]);
	}

	printf("%.6f\n", ans);
	return 0;
}
0