結果
| 問題 |
No.732 3PrimeCounting
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-03-20 19:34:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,535 bytes |
| コンパイル時間 | 1,052 ms |
| コンパイル使用メモリ | 112,000 KB |
| 実行使用メモリ | 11,904 KB |
| 最終ジャッジ日時 | 2024-07-05 03:30:31 |
| 合計ジャッジ時間 | 7,308 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 54 TLE * 1 -- * 34 |
ソースコード
#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;
//logが付くけどsetを使うのか?
//O(π(N)^2 log N)≒10^8
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);
set<int>sum;
for (int a : prime)
{
for (int b : prime)
{
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]++;
}
}
}
ll ans = 0;
//a,bを総当たり
for (int a : prime)
{
for (int b : prime)
{
//cとして考えられる数を総当たり
ans += crush[a + b];
}
}
//2つの素数を含む組みを消す
for (int a : prime)
{
ans -= crush[a + a] * 3;
}
cout << ans / 6 << endl;
return 0;
}