結果

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

テストケース

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