結果
| 問題 | No.843 Triple Primes |
| コンテスト | |
| ユーザー |
a01sa01to
|
| 提出日時 | 2025-04-08 00:48:38 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 2,000 ms |
| コード長 | 761 bytes |
| 記録 | |
| コンパイル時間 | 1,973 ms |
| コンパイル使用メモリ | 339,028 KB |
| 実行使用メモリ | 9,228 KB |
| 最終ジャッジ日時 | 2026-07-08 13:35:14 |
| 合計ジャッジ時間 | 4,877 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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