結果

問題 No.843 Triple Primes
ユーザー MarcusAureliusAntoninusMarcusAureliusAntoninus
提出日時 2019-06-28 21:38:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,332 ms / 2,000 ms
コード長 619 bytes
コンパイル時間 2,870 ms
コンパイル使用メモリ 205,540 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 17:37:57
合計ジャッジ時間 27,597 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1,332 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 887 ms
4,348 KB
testcase_08 AC 1,039 ms
4,348 KB
testcase_09 AC 1,307 ms
4,348 KB
testcase_10 AC 951 ms
4,348 KB
testcase_11 AC 1,129 ms
4,348 KB
testcase_12 AC 1,260 ms
4,348 KB
testcase_13 AC 1,193 ms
4,348 KB
testcase_14 AC 1,199 ms
4,348 KB
testcase_15 AC 912 ms
4,348 KB
testcase_16 AC 939 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 123 ms
4,348 KB
testcase_21 AC 43 ms
4,348 KB
testcase_22 AC 449 ms
4,348 KB
testcase_23 AC 484 ms
4,348 KB
testcase_24 AC 136 ms
4,348 KB
testcase_25 AC 83 ms
4,348 KB
testcase_26 AC 1,305 ms
4,348 KB
testcase_27 AC 10 ms
4,348 KB
testcase_28 AC 1,218 ms
4,348 KB
testcase_29 AC 155 ms
4,348 KB
testcase_30 AC 1,271 ms
4,348 KB
testcase_31 AC 20 ms
4,348 KB
testcase_32 AC 8 ms
4,348 KB
testcase_33 AC 183 ms
4,348 KB
testcase_34 AC 386 ms
4,348 KB
testcase_35 AC 1,312 ms
4,348 KB
testcase_36 AC 70 ms
4,348 KB
testcase_37 AC 823 ms
4,348 KB
testcase_38 AC 602 ms
4,348 KB
testcase_39 AC 1,238 ms
4,348 KB
testcase_40 AC 1 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 986 ms
4,348 KB
testcase_43 AC 1,127 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int main()
{
	int N;
	scanf("%d", &N);
	std::vector<bool> isPrime(N + 1, true);
	std::vector<int64_t> primeList;
	isPrime[0] = isPrime[1] = false;
	for (int64_t i{2}; i <= N; i++)
	{
		if (!isPrime[i]) continue;
		primeList.push_back(i);
		for (int64_t j{2 * i}; j <= N; j += i)
			isPrime[j] = false;
	}
	int64_t count{};
	for (int p_i{}; p_i < (int)primeList.size(); p_i++)
		for (int r_i{}; r_i < (int)primeList.size(); r_i++)
		{
			int64_t q{primeList[r_i] * primeList[r_i] - primeList[p_i]};
			if (2 <= q && q <= N && isPrime[q])
				count++;
		}
	printf("%lld\n", count);

	return 0;
}
0