結果

問題 No.144 エラトステネスのざる
ユーザー tubo28tubo28
提出日時 2015-02-06 00:07:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 2,733 bytes
コンパイル時間 1,144 ms
コンパイル使用メモリ 143,336 KB
実行使用メモリ 11,896 KB
最終ジャッジ日時 2023-09-05 13:22:48
合計ジャッジ時間 2,438 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 46 ms
11,684 KB
testcase_14 AC 47 ms
11,684 KB
testcase_15 AC 47 ms
11,696 KB
testcase_16 AC 47 ms
11,896 KB
testcase_17 AC 47 ms
11,876 KB
testcase_18 AC 51 ms
11,816 KB
testcase_19 AC 48 ms
11,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> istream& operator>>(istream& is, vector<T>& v);
template<class T> ostream& operator<<(ostream& os, vector<T> const& v);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream&, const tuple<T...>&){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream& os, const tuple<T...>& t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream& operator<<(ostream& os, const tuple<T...>& t){ _ot<0>(os, t); return os; }
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _it(istream&, tuple<T...>&){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _it(istream& is, tuple<T...>& t){ is >> get<n>(t); _it<n+1>(is, t); }
template<class...T> istream& operator>>(istream& is, tuple<T...>& t){ _it<0>(is, t); return is; }
template<class T> istream& operator>>(istream& is, vector<T>& v){ rep(i,v.size()) is >> v[i]; return is; }
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif

int N;
double p;
int cnt[1000010];
double dp[1000010];

int main(){
    while(cin>>N>>p){
        // for(int i=2;i<=N;i++){
        //     dp[i] = 1;
        //     for(int j=2;j*j<=i;j++){
        //         if(i%j==0){
        //             dp[i] *= (1-p)*dp[j];
        //             if(j*j!=i) dp[i] *= (1-p)*dp[i/j];
        //         }
        //     }
        // }
        for(int i=2;i<=N;i++) dp[i] = 1;
        for(int i=2;i<=N;i++){
            for(int j=i+i; j<=N; j+=i){
                dp[j] *= 1-p;
            }
        }
        double ans = 0;
        for(int i=2;i<=N;i++){
            ans += dp[i];
        }
        printf("%.10lf\n", ans);
    }
}

//     memset(cnt,0,sizeof(cnt));
//     for(int i=2;i<=1000000;i++){
//         for(int j=i; j<=1000000; j+=i){
//             cnt[j]++;
//         }
//     }

//     dump(vi(cnt, cnt+20));
//     while(cin>>N>>p){
//         double ans = 0;
//         for(int i=2;i<=N;i++){
//             dump(pow(p,cnt[i]));
//             ans += 1-pow(1-p,cnt[i]-1);
//         }
//         printf("%.10lf\n", ans);
//     }
// }
0