結果
問題 | No.144 エラトステネスのざる |
ユーザー |
![]() |
提出日時 | 2018-03-16 17:22:18 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 56 ms / 2,000 ms |
コード長 | 569 bytes |
コンパイル時間 | 343 ms |
コンパイル使用メモリ | 25,344 KB |
実行使用メモリ | 5,632 KB |
最終ジャッジ日時 | 2024-12-21 14:30:42 |
合計ジャッジ時間 | 1,540 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:16:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 16 | scanf("%d%lf", &n, &p); | ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>double power(double x, int n) {if (n == 0) return 1;if (n & 1) return x * power(x, n - 1);return power(x * x, n >> 1);}int ynum[1000001];int main() {int n; double p;int i, j;double ans = 0;scanf("%d%lf", &n, &p);for (i = 2; i <= n; i++) ynum[i] = 1;for (i = 2; i <= n; i++) {if (ynum[i] == 1) {for (j = i; j <= n; j += i) {int t = j, cnt = 0;while (t % i == 0) {t /= i;cnt++;}ynum[j] *= (cnt + 1);}}ans += power(1.0 - p, ynum[i] - 2);}printf("%.14f\n", ans);return 0;}