結果
問題 |
No.843 Triple Primes
|
ユーザー |
![]() |
提出日時 | 2020-07-18 09:07:15 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 13 ms / 2,000 ms |
コード長 | 526 bytes |
コンパイル時間 | 2,990 ms |
コンパイル使用メモリ | 195,644 KB |
最終ジャッジ日時 | 2025-01-12 00:09:36 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 42 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<bool> B(N + 1, true); B.at(0) = B.at(1) = false; for (int i = 2; i <= N; i++) { if (!B.at(i)) continue; for (int j = i + i; j <= N; j += i) B.at(j) = false; } long ans = 0; for (int i = 2; i <= N; i++) { if (!B.at(i)) continue; long tmp = i + 2; if (sqrt(tmp) == (long) sqrt(tmp)) { long tmp2 = sqrt(tmp); if (tmp2 <= N && B.at(tmp2)) ans += (i == 2) ? 1 : 2; } } cout << ans << "\n"; }