結果

問題 No.144 エラトステネスのざる
ユーザー pitsu_kyo_propitsu_kyo_pro
提出日時 2019-12-21 15:29:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 985 bytes
コンパイル時間 1,567 ms
コンパイル使用メモリ 166,632 KB
実行使用メモリ 7,216 KB
最終ジャッジ日時 2023-09-26 17:24:05
合計ジャッジ時間 2,950 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 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 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 57 ms
7,068 KB
testcase_14 AC 75 ms
7,044 KB
testcase_15 AC 82 ms
7,216 KB
testcase_16 AC 78 ms
7,128 KB
testcase_17 AC 78 ms
7,048 KB
testcase_18 AC 81 ms
7,052 KB
testcase_19 AC 51 ms
7,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1LL << 60;
constexpr int INF = 1000000007;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
  int N;
  double p;
  cin >> N >> p;
  double ans=0.0;
  vector<int> divisor(N+1,0);
  for(int i=2; i<=N; i++){
    for(int j=i; j<=N; j+=i){
      divisor[j]++;
    }
    ans += pow(1-p, divisor[i]-1);
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}
0