結果

問題 No.732 3PrimeCounting
ユーザー platypus999platypus999
提出日時 2017-03-20 19:32:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,643 bytes
コンパイル時間 1,101 ms
コンパイル使用メモリ 111,216 KB
実行使用メモリ 13,024 KB
最終ジャッジ日時 2023-09-18 12:42:18
合計ジャッジ時間 30,451 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,756 KB
testcase_01 AC 4 ms
4,380 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 5 ms
4,380 KB
testcase_04 AC 5 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 5 ms
4,376 KB
testcase_21 AC 11 ms
4,380 KB
testcase_22 AC 11 ms
4,380 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 26 ms
4,380 KB
testcase_26 AC 17 ms
4,380 KB
testcase_27 AC 5 ms
4,380 KB
testcase_28 AC 6 ms
4,376 KB
testcase_29 AC 8 ms
4,376 KB
testcase_30 AC 8 ms
4,380 KB
testcase_31 AC 12 ms
4,380 KB
testcase_32 AC 19 ms
4,376 KB
testcase_33 AC 19 ms
4,380 KB
testcase_34 AC 20 ms
4,380 KB
testcase_35 AC 13 ms
4,376 KB
testcase_36 AC 14 ms
4,376 KB
testcase_37 AC 5 ms
4,376 KB
testcase_38 AC 4 ms
4,380 KB
testcase_39 AC 14 ms
4,376 KB
testcase_40 AC 13 ms
4,380 KB
testcase_41 AC 13 ms
4,376 KB
testcase_42 AC 13 ms
4,380 KB
testcase_43 AC 10 ms
4,376 KB
testcase_44 AC 10 ms
4,380 KB
testcase_45 AC 6 ms
4,380 KB
testcase_46 AC 6 ms
4,380 KB
testcase_47 AC 7 ms
4,376 KB
testcase_48 AC 29 ms
4,380 KB
testcase_49 AC 29 ms
4,380 KB
testcase_50 AC 11 ms
4,380 KB
testcase_51 AC 11 ms
4,376 KB
testcase_52 AC 6 ms
4,376 KB
testcase_53 AC 91 ms
4,376 KB
testcase_54 AC 1,976 ms
6,224 KB
testcase_55 AC 1,991 ms
6,148 KB
testcase_56 AC 1,980 ms
6,092 KB
testcase_57 AC 319 ms
4,380 KB
testcase_58 AC 320 ms
4,376 KB
testcase_59 AC 102 ms
4,380 KB
testcase_60 AC 505 ms
4,600 KB
testcase_61 AC 506 ms
4,604 KB
testcase_62 AC 2,666 ms
6,552 KB
testcase_63 AC 1,029 ms
5,784 KB
testcase_64 AC 676 ms
4,824 KB
testcase_65 AC 674 ms
4,812 KB
testcase_66 AC 4 ms
4,380 KB
testcase_67 AC 4 ms
4,376 KB
testcase_68 AC 2,290 ms
6,492 KB
testcase_69 AC 2,275 ms
6,184 KB
testcase_70 AC 2,026 ms
6,276 KB
testcase_71 AC 2,017 ms
6,168 KB
testcase_72 AC 952 ms
4,948 KB
testcase_73 TLE -
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;

//unordered_setを使って高速化できるのだろうか
//O(π(N)×μ(N))≒10^8
//(μ(N)は1~Nまでの素数2つの和として表せる数の個数とする)
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;
	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