結果
問題 |
No.144 エラトステネスのざる
|
ユーザー |
|
提出日時 | 2022-08-06 23:45:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 47 ms / 2,000 ms |
コード長 | 409 bytes |
コンパイル時間 | 630 ms |
コンパイル使用メモリ | 75,220 KB |
実行使用メモリ | 11,392 KB |
最終ジャッジ日時 | 2024-09-16 17:28:22 |
合計ジャッジ時間 | 1,697 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <iostream> #include <iomanip> #include <vector> using namespace std; int main(){ int n; double p; cin>>n>>p; vector<double> candidate(n+1,1.0); double ans=0; for(int i=2;i<=n;i++){ if (candidate[i]<0) continue; ans+=candidate[i]; int next_cur=i*2; while(next_cur<=n){ candidate[next_cur]*=(1-p); next_cur+=i; } } cout<<fixed<<setprecision(10); cout<<ans<<endl; return 0; }