結果
問題 |
No.732 3PrimeCounting
|
ユーザー |
|
提出日時 | 2017-03-20 19:50:03 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,488 bytes |
コンパイル時間 | 1,079 ms |
コンパイル使用メモリ | 113,788 KB |
実行使用メモリ | 13,880 KB |
最終ジャッジ日時 | 2024-07-05 04:32:10 |
合計ジャッジ時間 | 52,412 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 85 TLE * 3 -- * 1 |
ソースコード
#include <cstdio> #include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <cstring> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <complex> #include <stack> #include <queue> #include <unordered_set> #include <unordered_map> using namespace std; using ll = long long; const ll PMAX = 300000; //わからん、全然わからん int main(void) { int n; vector<int>prime; vector<bool>flag(PMAX); cin >> n; //primeにn以下のすべての素数が入る //flag[i-2]はiが素数の時false for (int x = 2; x <= PMAX; ++x) { if (flag[x - 2])continue; if (x <= n)prime.push_back(x); for (int y = x + x; y <= PMAX; y += x) { flag[y - 2] = true; } } vector<int>crush(n + n + 1); unordered_set<int>sum; ll ans = 0; for (int a : prime) { for (int b : prime) { if (a < b)break; sum.insert(a + b); } } //crush[x]:=N以下の素数pのうち、x+pも素数である個数。 //xが2つの素数の和で表せる場合のみを算出 for (int x : sum) { for (int p : prime) { if (!flag[p + x - 2]) { crush[x]++; } } } //a,bを総当たり for (int a : prime) { for (int b : prime) { if (a < b)break; //いろいろ定数倍を落とすために頑張る ans += crush[a + b] * ((a != b) ? 2 : -2); } } cout << ans / 6 << endl; return 0; }