結果
| 問題 |
No.843 Triple Primes
|
| コンテスト | |
| ユーザー |
a01sa01to
|
| 提出日時 | 2025-04-08 00:48:38 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 16 ms / 2,000 ms |
| コード長 | 761 bytes |
| コンパイル時間 | 3,653 ms |
| コンパイル使用メモリ | 280,888 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-04-08 00:48:44 |
| 合計ジャッジ時間 | 5,747 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 42 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "settings/debug.cpp"
#else
#define Debug(...) void(0)
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
if (n == 1) {
cout << 0 << '\n';
return 0;
}
vector<bool> is_prime(n + 1, true);
set<int> primes;
is_prime[0] = is_prime[1] = false;
for (ll i = 2; i <= n; ++i) {
if (is_prime[i]) {
primes.insert(i);
for (ll j = i * i; j <= n; j += i) is_prime[j] = false;
}
}
int ans = -1;
for (ll x : primes) {
if (x * x - 2 <= n && primes.contains(x * x - 2)) ans += 2;
}
cout << ans << '\n';
return 0;
}
a01sa01to