結果
問題 | No.843 Triple Primes |
ユーザー |
![]() |
提出日時 | 2020-06-05 08:32:51 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 734 bytes |
コンパイル時間 | 1,782 ms |
コンパイル使用メモリ | 176,756 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-14 17:03:13 |
合計ジャッジ時間 | 3,061 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 40 WA * 2 |
ソースコード
#include <bits/stdc++.h>#define rep(i,n) for(int i=(0);i<(n);i++)using namespace std;typedef long long ll;int main(){cin.tie(0);ios::sync_with_stdio(false);ll n;cin >> n;if(n == 1){cout << 0 << endl;exit(0);}int max_n = 505050;vector<bool> isprime(max_n, true);vector<ll> primes;isprime[0] = isprime[1] = false;for(int i = 2; i < max_n; i++){if(isprime[i]){primes.push_back(i);for(int j = 2 * i; j < max_n; j += i) isprime[j] = false;}}set<ll> psq;for(ll p : primes){if(p * p > n) break;psq.insert(p * p);}// (2, 2, 2)ll ans = 1;for(ll p : primes){if(p == 2) continue;if(p > n) break;if(psq.count(p + 2) == 1) ans += 2;}cout << ans << endl;}