結果

問題 No.144 エラトステネスのざる
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-04 06:28:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 694 ms / 2,000 ms
コード長 486 bytes
コンパイル時間 1,236 ms
コンパイル使用メモリ 143,784 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 04:03:45
合計ジャッジ時間 7,062 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

int main() {
	int N;
	double p;
	cin >> N >> p;
	double ans = 0;
	for (int i = 2; i <= N; i++)
	{
		int divisor = 1;
		int temp = i;
		for (int j = 2; j * j <= temp; j++)
		{
			if (temp % j == 0){
				int count = 0;
				while (temp%j == 0){
					count++; temp /= j;
				}
				divisor *= count + 1;
			}
		}
		if (temp != 1) divisor *= 2;
		if (divisor == 2) ans += 1;
		else ans += pow(1 - p, divisor - 2);

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