結果

問題 No.732 3PrimeCounting
ユーザー platypus999platypus999
提出日時 2017-03-20 19:50:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,488 bytes
コンパイル時間 1,620 ms
コンパイル使用メモリ 111,716 KB
実行使用メモリ 8,592 KB
最終ジャッジ日時 2023-09-18 13:21:01
合計ジャッジ時間 54,519 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,380 KB
testcase_01 AC 4 ms
4,380 KB
testcase_02 AC 4 ms
4,380 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 4 ms
4,380 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 5 ms
4,376 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 5 ms
4,380 KB
testcase_19 AC 4 ms
4,376 KB
testcase_20 AC 5 ms
4,376 KB
testcase_21 AC 11 ms
4,376 KB
testcase_22 AC 11 ms
4,376 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 5 ms
4,380 KB
testcase_25 AC 24 ms
4,380 KB
testcase_26 AC 15 ms
4,376 KB
testcase_27 AC 5 ms
4,376 KB
testcase_28 AC 5 ms
4,376 KB
testcase_29 AC 8 ms
4,380 KB
testcase_30 AC 8 ms
4,376 KB
testcase_31 AC 11 ms
4,376 KB
testcase_32 AC 17 ms
4,376 KB
testcase_33 AC 17 ms
4,376 KB
testcase_34 AC 18 ms
4,376 KB
testcase_35 AC 12 ms
4,380 KB
testcase_36 AC 13 ms
4,376 KB
testcase_37 AC 4 ms
4,376 KB
testcase_38 AC 4 ms
4,380 KB
testcase_39 AC 13 ms
4,380 KB
testcase_40 AC 12 ms
4,380 KB
testcase_41 AC 12 ms
4,376 KB
testcase_42 AC 12 ms
4,376 KB
testcase_43 AC 9 ms
4,380 KB
testcase_44 AC 9 ms
4,380 KB
testcase_45 AC 6 ms
4,376 KB
testcase_46 AC 6 ms
4,376 KB
testcase_47 AC 6 ms
4,376 KB
testcase_48 AC 27 ms
4,380 KB
testcase_49 AC 26 ms
4,376 KB
testcase_50 AC 10 ms
4,376 KB
testcase_51 AC 11 ms
4,376 KB
testcase_52 AC 6 ms
4,380 KB
testcase_53 AC 82 ms
4,376 KB
testcase_54 AC 1,733 ms
6,196 KB
testcase_55 AC 1,741 ms
6,176 KB
testcase_56 AC 1,737 ms
6,396 KB
testcase_57 AC 286 ms
4,512 KB
testcase_58 AC 287 ms
4,396 KB
testcase_59 AC 93 ms
4,376 KB
testcase_60 AC 452 ms
4,612 KB
testcase_61 AC 453 ms
4,688 KB
testcase_62 AC 2,337 ms
6,492 KB
testcase_63 AC 921 ms
5,800 KB
testcase_64 AC 607 ms
4,668 KB
testcase_65 AC 605 ms
4,672 KB
testcase_66 AC 4 ms
4,380 KB
testcase_67 AC 5 ms
4,376 KB
testcase_68 AC 2,000 ms
6,188 KB
testcase_69 AC 2,001 ms
6,436 KB
testcase_70 AC 1,771 ms
6,108 KB
testcase_71 AC 1,769 ms
6,100 KB
testcase_72 AC 853 ms
4,980 KB
testcase_73 TLE -
testcase_74 TLE -
testcase_75 AC 23 ms
4,376 KB
testcase_76 AC 1,946 ms
6,132 KB
testcase_77 AC 317 ms
4,384 KB
testcase_78 AC 2,969 ms
7,072 KB
testcase_79 AC 2,027 ms
6,172 KB
testcase_80 AC 2,624 ms
6,484 KB
testcase_81 AC 1,793 ms
6,208 KB
testcase_82 AC 5 ms
4,384 KB
testcase_83 AC 301 ms
4,376 KB
testcase_84 AC 343 ms
4,380 KB
testcase_85 AC 1,476 ms
5,816 KB
testcase_86 AC 2,688 ms
6,732 KB
testcase_87 TLE -
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;

//わからん、全然わからん
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;
}
0