結果
| 問題 |
No.843 Triple Primes
|
| コンテスト | |
| ユーザー |
lowr
|
| 提出日時 | 2019-08-16 19:49:13 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 633 bytes |
| コンパイル時間 | 2,073 ms |
| コンパイル使用メモリ | 195,948 KB |
| 最終ジャッジ日時 | 2025-01-07 12:07:57 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 39 WA * 3 |
ソースコード
#include <bits/stdc++.h>
using i64 = long long;
int main() {
int n;
std::cin >> n;
std::vector<int> ps;
std::vector<int> comp(n + 1);
for (int i = 2; i < n; i++) {
if (!comp[i]) ps.push_back(i);
for (int j = 0; j < ps.size() && i * ps[j] < n; j++) {
comp[i * ps[j]] = 1;
if (i % ps[j] == 0) break;
}
}
int ret = 0;
for (auto p : ps) {
auto t = p * p - 2;
if (p > n || t > n) break;
auto it = std::lower_bound(ps.begin(), ps.end(), t);
if (it != ps.end() && *it == t) {
if (t == p) ret++;
else ret += 2;
}
}
std::cout << ret << std::endl;
return 0;
}
lowr