結果

問題 No.144 エラトステネスのざる
ユーザー bachoppibachoppi
提出日時 2020-09-17 23:16:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 279 ms / 2,000 ms
コード長 950 bytes
コンパイル時間 979 ms
コンパイル使用メモリ 116,972 KB
実行使用メモリ 23,188 KB
最終ジャッジ日時 2023-09-04 08:01:35
合計ジャッジ時間 2,782 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
7,380 KB
testcase_01 AC 30 ms
7,504 KB
testcase_02 AC 30 ms
7,516 KB
testcase_03 AC 30 ms
7,444 KB
testcase_04 AC 29 ms
7,516 KB
testcase_05 AC 30 ms
7,476 KB
testcase_06 AC 31 ms
7,484 KB
testcase_07 AC 30 ms
7,584 KB
testcase_08 AC 30 ms
7,388 KB
testcase_09 AC 30 ms
7,524 KB
testcase_10 AC 30 ms
7,516 KB
testcase_11 AC 31 ms
7,532 KB
testcase_12 AC 30 ms
7,380 KB
testcase_13 AC 38 ms
23,152 KB
testcase_14 AC 37 ms
23,188 KB
testcase_15 AC 279 ms
23,120 KB
testcase_16 AC 36 ms
23,144 KB
testcase_17 AC 37 ms
23,116 KB
testcase_18 AC 37 ms
23,188 KB
testcase_19 AC 36 ms
23,132 KB
権限があれば一括ダウンロードができます

ソースコード

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