結果

問題 No.843 Triple Primes
ユーザー claw88claw88
提出日時 2019-06-28 21:36:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,651 bytes
コンパイル時間 1,565 ms
コンパイル使用メモリ 166,200 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 21:41:12
合計ジャッジ時間 7,510 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 RE -
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 RE -
testcase_21 AC 41 ms
4,380 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 10 ms
4,376 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 AC 18 ms
4,376 KB
testcase_32 AC 8 ms
4,376 KB
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 AC 66 ms
4,380 KB
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 RE -
testcase_43 RE -
権限があれば一括ダウンロードができます

ソースコード

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 100000
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