結果

問題 No.732 3PrimeCounting
ユーザー platypus999platypus999
提出日時 2017-03-20 19:34:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,535 bytes
コンパイル時間 1,005 ms
コンパイル使用メモリ 109,480 KB
実行使用メモリ 11,532 KB
最終ジャッジ日時 2023-09-18 12:43:04
合計ジャッジ時間 22,700 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,376 KB
testcase_01 AC 4 ms
4,376 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 4 ms
4,384 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 4 ms
4,384 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 5 ms
4,380 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 16 ms
4,376 KB
testcase_22 AC 17 ms
4,376 KB
testcase_23 AC 4 ms
4,384 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 44 ms
4,380 KB
testcase_26 AC 26 ms
4,380 KB
testcase_27 AC 6 ms
4,380 KB
testcase_28 AC 6 ms
4,376 KB
testcase_29 AC 12 ms
4,384 KB
testcase_30 AC 12 ms
4,380 KB
testcase_31 AC 18 ms
4,376 KB
testcase_32 AC 31 ms
4,380 KB
testcase_33 AC 31 ms
4,380 KB
testcase_34 AC 31 ms
4,380 KB
testcase_35 AC 21 ms
4,380 KB
testcase_36 AC 21 ms
4,376 KB
testcase_37 AC 4 ms
4,376 KB
testcase_38 AC 5 ms
4,380 KB
testcase_39 AC 23 ms
4,380 KB
testcase_40 AC 19 ms
4,380 KB
testcase_41 AC 19 ms
4,376 KB
testcase_42 AC 20 ms
4,380 KB
testcase_43 AC 14 ms
4,380 KB
testcase_44 AC 14 ms
4,384 KB
testcase_45 AC 7 ms
4,380 KB
testcase_46 AC 7 ms
4,380 KB
testcase_47 AC 9 ms
4,380 KB
testcase_48 AC 49 ms
4,380 KB
testcase_49 AC 49 ms
4,376 KB
testcase_50 AC 16 ms
4,380 KB
testcase_51 AC 17 ms
4,380 KB
testcase_52 AC 6 ms
4,380 KB
testcase_53 AC 165 ms
4,376 KB
testcase_54 TLE -
testcase_55 TLE -
testcase_56 TLE -
testcase_57 AC 592 ms
4,472 KB
testcase_58 AC 596 ms
4,568 KB
testcase_59 AC 186 ms
4,376 KB
testcase_60 AC 952 ms
4,776 KB
testcase_61 AC 955 ms
4,828 KB
testcase_62 TLE -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0