結果

問題 No.843 Triple Primes
ユーザー QCFiumQCFium
提出日時 2019-06-28 21:36:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 357 ms / 2,000 ms
コード長 642 bytes
コンパイル時間 1,937 ms
コンパイル使用メモリ 172,760 KB
実行使用メモリ 7,600 KB
最終ジャッジ日時 2023-10-19 17:32:30
合計ジャッジ時間 10,668 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,652 KB
testcase_01 AC 354 ms
7,600 KB
testcase_02 AC 8 ms
5,692 KB
testcase_03 AC 7 ms
5,680 KB
testcase_04 AC 9 ms
5,708 KB
testcase_05 AC 8 ms
5,684 KB
testcase_06 AC 8 ms
5,712 KB
testcase_07 AC 266 ms
7,244 KB
testcase_08 AC 308 ms
7,380 KB
testcase_09 AC 350 ms
7,592 KB
testcase_10 AC 283 ms
7,300 KB
testcase_11 AC 320 ms
7,452 KB
testcase_12 AC 353 ms
7,552 KB
testcase_13 AC 337 ms
7,500 KB
testcase_14 AC 338 ms
7,504 KB
testcase_15 AC 271 ms
7,268 KB
testcase_16 AC 282 ms
7,288 KB
testcase_17 AC 7 ms
5,652 KB
testcase_18 AC 7 ms
5,652 KB
testcase_19 AC 7 ms
5,656 KB
testcase_20 AC 60 ms
6,240 KB
testcase_21 AC 29 ms
5,992 KB
testcase_22 AC 150 ms
6,784 KB
testcase_23 AC 163 ms
6,828 KB
testcase_24 AC 65 ms
6,272 KB
testcase_25 AC 45 ms
6,136 KB
testcase_26 AC 352 ms
7,588 KB
testcase_27 AC 14 ms
5,796 KB
testcase_28 AC 352 ms
7,520 KB
testcase_29 AC 68 ms
6,312 KB
testcase_30 AC 357 ms
7,560 KB
testcase_31 AC 19 ms
5,872 KB
testcase_32 AC 13 ms
5,780 KB
testcase_33 AC 77 ms
6,372 KB
testcase_34 AC 137 ms
6,700 KB
testcase_35 AC 353 ms
7,592 KB
testcase_36 AC 39 ms
6,088 KB
testcase_37 AC 249 ms
7,188 KB
testcase_38 AC 198 ms
6,964 KB
testcase_39 AC 345 ms
7,536 KB
testcase_40 AC 7 ms
5,652 KB
testcase_41 AC 7 ms
5,652 KB
testcase_42 AC 293 ms
7,336 KB
testcase_43 AC 316 ms
7,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int is_prime[500001];

int main() {
	int n = ri();
	for (int i = 2; i <= 500000; i++) is_prime[i] = true;
	for (int i = 2; i <= 500000; i++) {
		if (!is_prime[i]) continue;
		for (int j = 2; j * i <= 500000; j++)
			is_prime[j * i] = false;
	}
	std::set<int64_t> primes;
	for (int i = 2; i <= n; i++) if (is_prime[i]) primes.insert(i);
	int res = 0;
	for (auto i : primes) {
		int64_t pow2 = (int64_t) i * i;
		if (pow2 > 2 * n) continue;
		for (auto j : primes) if (pow2 - j <= n && primes.count(pow2 - j)) res++;
	}
	std::cout << res << std::endl;
	
	return 0;
}

0