結果

問題 No.144 エラトステネスのざる
ユーザー a0171610a0171610
提出日時 2020-05-19 21:39:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 750 bytes
コンパイル時間 1,342 ms
コンパイル使用メモリ 164,300 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-09 22:28:15
合計ジャッジ時間 2,189 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
6,940 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 25 ms
9,980 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 25 ms
10,844 KB
testcase_19 AC 25 ms
9,264 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:25:7: warning: 'ans' is used uninitialized [-Wuninitialized]
   25 |   ans += double(p);
      |   ~~~~^~~~~~~~~~~~
main.cpp:24:10: note: 'ans' was declared here
   24 |   double ans;
      |          ^~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const int MAX_N = 1e6+10;
int prime[MAX_N], dataset[MAX_N];
bool is_prime[MAX_N];
int p = 0;

void sieve(int n){
  for(int i = 0; i < n; i++) is_prime[i] = true;
  is_prime[0] = false; is_prime[1] = false;
  for(int i = 2; i <= n; i++){
    if(is_prime[i]){
      prime[p++] = i;
      for(int j = 2 * i; j <= n; j += i) is_prime[j] = false, dataset[j]++;
    }
  }
}

signed main(){
  int n; cin >> n;
  double P; cin >> P;
  sieve(n);
  double ans;
  ans += double(p);
  for(int i = 0; i <= n; i++){
    if(dataset[i]){
      double ans1 = 1;
      for(int j = 0; j < dataset[i]; j++) ans1 *= (1.0 - P);
      ans += ans1;
    }
  }
  cout << setprecision(10) << ans << endl;
}
0