結果
| 問題 |
No.144 エラトステネスのざる
|
| コンテスト | |
| ユーザー |
rsk0315
|
| 提出日時 | 2019-03-17 19:10:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,462 ms / 2,000 ms |
| コード長 | 381 bytes |
| コンパイル時間 | 271 ms |
| コンパイル使用メモリ | 47,488 KB |
| 最終ジャッジ日時 | 2025-01-06 22:34:17 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:7:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
7 | scanf("%d %lf", &N, &p);
| ~~~~~^~~~~~~~~~~~~~~~~~
ソースコード
#include <cstdio>
#include <vector>
int main() {
int N;
double p;
scanf("%d %lf", &N, &p);
std::vector<double> zaru(N+1, 1.0);
double res = 0;
for (int i = 2; i <= N; ++i) {
res += zaru[i];
for (int j = i+i; j <= N; j += i)
zaru[j] *= 1-p;
}
for (int i = 2; i <= N; ++i)
fprintf(stderr, "%2d: %.6f\n", i, zaru[i]);
printf("%.12f\n", res);
}
rsk0315