結果

問題 No.144 エラトステネスのざる
ユーザー bachoppibachoppi
提出日時 2020-09-17 23:16:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 253 ms / 2,000 ms
コード長 950 bytes
コンパイル時間 1,077 ms
コンパイル使用メモリ 116,440 KB
最終ジャッジ日時 2025-01-14 15:43:20
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793



int main(){
  int n; long double p; cin >> n >> p; 
  int cnt[1010100] = {};
  for(int i=2; i<=1010000; i++){
    for(int j=2*i; j<=1010000; j+=i){
      cnt[j]++;
    }
  }
  long double ans = 0.0;
  long double pow[n];
  pow[0] = 1.0;
  rep(i, n){
    pow[i+1] = pow[i]*(1-p);
  }
  for(int i=2; i<=n; i++){
    ans+=pow[cnt[i]];
    //cout << ans << endl;
  }
  cout << fixed << setprecision(7) << ans << endl;
}
  
  
0