結果

問題 No.144 エラトステネスのざる
ユーザー imulanimulan
提出日時 2016-02-04 03:15:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 523 ms / 2,000 ms
コード長 1,131 bytes
コンパイル時間 1,300 ms
コンパイル使用メモリ 161,824 KB
実行使用メモリ 4,980 KB
最終ジャッジ日時 2023-10-21 18:57:37
合計ジャッジ時間 6,076 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
4,980 KB
testcase_01 AC 10 ms
4,980 KB
testcase_02 AC 9 ms
4,980 KB
testcase_03 AC 9 ms
4,980 KB
testcase_04 AC 9 ms
4,980 KB
testcase_05 AC 10 ms
4,980 KB
testcase_06 AC 9 ms
4,980 KB
testcase_07 AC 10 ms
4,980 KB
testcase_08 AC 9 ms
4,980 KB
testcase_09 AC 10 ms
4,980 KB
testcase_10 AC 9 ms
4,980 KB
testcase_11 AC 10 ms
4,980 KB
testcase_12 AC 10 ms
4,980 KB
testcase_13 AC 520 ms
4,980 KB
testcase_14 AC 521 ms
4,980 KB
testcase_15 AC 523 ms
4,980 KB
testcase_16 AC 521 ms
4,980 KB
testcase_17 AC 520 ms
4,980 KB
testcase_18 AC 521 ms
4,980 KB
testcase_19 AC 520 ms
4,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define mp make_pair
#define pb push_back
#define fi first
#define sc second

int main(int argc, char const *argv[]) {
  bool prime[1000001];
  rep(i,1000001) prime[i]=true;
  prime[0]=prime[1]=false;
  for(int i=2; i<=1000000; ++i){
    if(prime[i]){
      for(int j=2; i*j<=1000000; ++j)
        prime[i*j]=false;
    }
  }

  //素数リスト
  vector<int> p;
  rep(i,1000000) if(prime[i]) p.pb(i);

  int n;
  double q;
  cin >>n >>q;

  double pw[1000];
  pw[0]=1;
  rep(i,999){
    pw[i+1]=pw[i]*(1-q);
    //printf("pw[%d]=%.40lf\n",i+1,pw[i+1] );
  }

  double ans=0.0;
  for(int i=2; i<=n; ++i){
    if(prime[i]) ans+=1.0;
    else{
      //約数の個数を数える
      int t=i;
      int j,c=1;
      for(int k=2; k*k<=t; ++k,c*=j){
        for(j=1; !(t%k); ++j){
          t/=k;
        }
      }
      if(1<t) c*=2;

      //printf(" %d: %d\n", i, c);
      ans+=pw[c-2];
    }
  }

  printf("%.10lf\n", ans);
  return 0;
}
0