結果

問題 No.843 Triple Primes
ユーザー claw88claw88
提出日時 2019-06-28 21:46:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,664 bytes
コンパイル時間 1,667 ms
コンパイル使用メモリ 166,900 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-14 21:53:23
合計ジャッジ時間 80,545 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,976 ms
4,376 KB
testcase_01 AC 1,978 ms
4,376 KB
testcase_02 AC 1,978 ms
4,376 KB
testcase_03 AC 1,976 ms
4,380 KB
testcase_04 AC 1,976 ms
4,380 KB
testcase_05 AC 1,979 ms
4,380 KB
testcase_06 AC 1,977 ms
4,380 KB
testcase_07 AC 1,980 ms
4,380 KB
testcase_08 AC 1,977 ms
4,380 KB
testcase_09 AC 1,977 ms
4,376 KB
testcase_10 AC 1,984 ms
4,380 KB
testcase_11 AC 1,983 ms
4,380 KB
testcase_12 AC 1,976 ms
4,376 KB
testcase_13 AC 1,979 ms
4,380 KB
testcase_14 AC 1,973 ms
4,380 KB
testcase_15 AC 1,981 ms
4,380 KB
testcase_16 AC 1,979 ms
4,384 KB
testcase_17 AC 1,981 ms
4,380 KB
testcase_18 AC 1,984 ms
4,380 KB
testcase_19 AC 1,982 ms
4,376 KB
testcase_20 AC 1,973 ms
4,376 KB
testcase_21 AC 1,982 ms
4,380 KB
testcase_22 AC 1,974 ms
4,376 KB
testcase_23 AC 1,975 ms
4,504 KB
testcase_24 AC 1,989 ms
4,384 KB
testcase_25 AC 1,994 ms
4,380 KB
testcase_26 TLE -
testcase_27 AC 1,984 ms
4,380 KB
testcase_28 AC 1,984 ms
4,384 KB
testcase_29 TLE -
testcase_30 TLE -
testcase_31 AC 1,979 ms
4,384 KB
testcase_32 AC 1,989 ms
4,380 KB
testcase_33 AC 1,997 ms
4,384 KB
testcase_34 AC 1,978 ms
4,376 KB
testcase_35 AC 1,977 ms
4,380 KB
testcase_36 AC 1,992 ms
4,380 KB
testcase_37 TLE -
testcase_38 AC 1,980 ms
4,380 KB
testcase_39 AC 1,978 ms
4,380 KB
testcase_40 AC 1,976 ms
4,384 KB
testcase_41 AC 1,992 ms
4,504 KB
testcase_42 AC 1,980 ms
4,380 KB
testcase_43 AC 1,974 ms
4,376 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];
constexpr 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()
{
	eratos(MAX);
	int N; cin >> 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