結果

問題 No.843 Triple Primes
ユーザー claw88claw88
提出日時 2019-06-28 21:37:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,307 ms / 2,000 ms
コード長 1,651 bytes
コンパイル時間 1,875 ms
コンパイル使用メモリ 169,448 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-22 10:19:10
合計ジャッジ時間 28,725 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1,305 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 3 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 AC 874 ms
6,676 KB
testcase_08 AC 1,031 ms
6,676 KB
testcase_09 AC 1,297 ms
6,676 KB
testcase_10 AC 933 ms
6,676 KB
testcase_11 AC 1,113 ms
6,676 KB
testcase_12 AC 1,241 ms
6,676 KB
testcase_13 AC 1,182 ms
6,676 KB
testcase_14 AC 1,187 ms
6,676 KB
testcase_15 AC 900 ms
6,676 KB
testcase_16 AC 922 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 121 ms
6,676 KB
testcase_21 AC 42 ms
6,676 KB
testcase_22 AC 447 ms
6,676 KB
testcase_23 AC 479 ms
6,676 KB
testcase_24 AC 136 ms
6,676 KB
testcase_25 AC 83 ms
6,676 KB
testcase_26 AC 1,300 ms
6,676 KB
testcase_27 AC 9 ms
6,676 KB
testcase_28 AC 1,204 ms
6,676 KB
testcase_29 AC 150 ms
6,676 KB
testcase_30 AC 1,255 ms
6,676 KB
testcase_31 AC 18 ms
6,676 KB
testcase_32 AC 8 ms
6,676 KB
testcase_33 AC 181 ms
6,676 KB
testcase_34 AC 385 ms
6,676 KB
testcase_35 AC 1,307 ms
6,676 KB
testcase_36 AC 67 ms
6,676 KB
testcase_37 AC 810 ms
6,676 KB
testcase_38 AC 593 ms
6,676 KB
testcase_39 AC 1,216 ms
6,676 KB
testcase_40 AC 2 ms
6,676 KB
testcase_41 AC 2 ms
6,676 KB
testcase_42 AC 975 ms
6,676 KB
testcase_43 AC 1,116 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
#define dom 998244353
#define all(c) begin(c),end(c)
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }
#define long long long
#define List vector
#define var auto
#define Count size()
#define Length size()
int dd[] = { 0, 1, 0, -1, 0 }; //→↓←↑

#define MAX 500000
vector<int> prime;
bool is_prime[MAX + 1];
void eratos(int n)
{
	rep(i, n + 1) is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	rep(i, n + 1)
	{
		if (is_prime[i])
		{
			prime.emplace_back(i);
			for (int j = 2 * i; j <= n; j += i)
				is_prime[j] = false;
		}
	}
}

// オイラーのファイ関数
// 自然数nに対し、1からnまでの自然数の中で
// nと互いに素なものの数 
//int P[MAX + 1];
//void phi(int n)
//{
//	for (int i = 0; i <= n; i++)
//		P[i] = i;
//	for (int i = 2; i <= n; i++)
//	{
//		if (is_prime[i])
//		{
//			P[i] -= P[i] / i;
//			for (int j = 2 * i; j <= n; j += i)
//				P[j] -= P[j] / i;
//		}
//	}
//}
void solve()
{
	int N; cin >> N;
	eratos(N);
	int cnt = 0;
	for (auto r : prime)
	{
		long L = (long)r * r;
		for (auto p : prime)
		{
			if (p > L / 2)
			{
				break;
			}
			if (L - p <= N && is_prime[L - p])
			{
				cnt++;
				if (L - p != p)cnt++;
			}
		}
	}
	cout << cnt << endl;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	return 0;
}
0