結果

問題 No.144 エラトステネスのざる
ユーザー 👑 horiesinitihoriesiniti
提出日時 2023-02-07 12:47:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 418 bytes
コンパイル時間 1,370 ms
コンパイル使用メモリ 62,972 KB
実行使用メモリ 19,352 KB
最終ジャッジ日時 2023-09-18 20:26:17
合計ジャッジ時間 2,766 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 81 ms
19,352 KB
testcase_14 AC 79 ms
19,332 KB
testcase_15 AC 82 ms
19,200 KB
testcase_16 AC 80 ms
19,332 KB
testcase_17 AC 82 ms
19,240 KB
testcase_18 AC 81 ms
19,296 KB
testcase_19 AC 82 ms
19,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
using namespace std;
long double rr[1000001];

int main() {
	int n;
	long double k;
	cin>>n>>k;
	k=1.0-k;
	for(int i=2;i<=n;i++){
		rr[i]=1.0;
	}
	for(int i=2;i<=n/2+3;i++){
		long double k2=k;
		int p=i*2;
		while(p<=n){
			rr[p]=rr[p]*k2;
			p+=i;
		}
	}
	long double ans=0.0;
	for(int i=2;i<=n;i++){
		ans+=rr[i];
	}
	cout << fixed <<setprecision(8) << ans<<endl;
	return 0;
}
0