結果

問題 No.144 エラトステネスのざる
ユーザー 古寺いろは
提出日時 2015-04-04 06:28:21
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 611 ms / 2,000 ms
コード長 486 bytes
コンパイル時間 1,284 ms
コンパイル使用メモリ 158,016 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-04 01:41:35
合計ジャッジ時間 6,027 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

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