結果
問題 |
No.144 エラトステネスのざる
|
ユーザー |
![]() |
提出日時 | 2018-05-28 10:42:03 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 54 ms / 2,000 ms |
コード長 | 749 bytes |
コンパイル時間 | 1,529 ms |
コンパイル使用メモリ | 166,612 KB |
実行使用メモリ | 7,916 KB |
最終ジャッジ日時 | 2024-06-30 07:37:56 |
合計ジャッジ時間 | 2,471 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
コンパイルメッセージ
main.cpp:21:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 21 | main(){ | ^~~~
ソースコード
#include<bits/stdc++.h> typedef long long ll; using namespace std; int INF = 1LL << 30; int MOD = 1e9+7; /* template<size_t max_N> struct P{ int count[max_N]; //size_t counter = 0; constexpr P() : count() { for(int i = 2; i <= max_N; ++i){ for(int j = i; j <= max_N; j += i){ count[j]++; } } } }; */ int cnt[1000010]; main(){ //constexpr auto c = P<10010>(); int N; double p; cin >> N >> p; for(int i = 2;i <= N;i++){ for(int j = i*2;j <= N;j += i){ cnt[j]++; } } double ans = 0; for(int i = 2;i <= N;i++){ if(cnt[i] == 0)ans += 1; else ans += pow(1 - p, cnt[i]); } printf("%.9lf\n" ,ans); }