結果

問題 No.843 Triple Primes
ユーザー ldsybldsyb
提出日時 2019-06-28 22:49:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 248 ms / 2,000 ms
コード長 612 bytes
コンパイル時間 1,538 ms
コンパイル使用メモリ 170,668 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 17:50:16
合計ジャッジ時間 7,573 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 248 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 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 183 ms
4,348 KB
testcase_08 AC 207 ms
4,348 KB
testcase_09 AC 246 ms
4,348 KB
testcase_10 AC 191 ms
4,348 KB
testcase_11 AC 220 ms
4,348 KB
testcase_12 AC 238 ms
4,348 KB
testcase_13 AC 229 ms
4,348 KB
testcase_14 AC 229 ms
4,348 KB
testcase_15 AC 185 ms
4,348 KB
testcase_16 AC 190 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 40 ms
4,348 KB
testcase_21 AC 18 ms
4,348 KB
testcase_22 AC 108 ms
4,348 KB
testcase_23 AC 115 ms
4,348 KB
testcase_24 AC 44 ms
4,348 KB
testcase_25 AC 31 ms
4,348 KB
testcase_26 AC 247 ms
4,348 KB
testcase_27 AC 6 ms
4,348 KB
testcase_28 AC 233 ms
4,348 KB
testcase_29 AC 48 ms
4,348 KB
testcase_30 AC 240 ms
4,348 KB
testcase_31 AC 10 ms
4,348 KB
testcase_32 AC 6 ms
4,348 KB
testcase_33 AC 55 ms
4,348 KB
testcase_34 AC 97 ms
4,348 KB
testcase_35 AC 246 ms
4,348 KB
testcase_36 AC 27 ms
4,348 KB
testcase_37 AC 171 ms
4,348 KB
testcase_38 AC 135 ms
4,348 KB
testcase_39 AC 239 ms
4,348 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 198 ms
4,348 KB
testcase_43 AC 218 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int64_t n;
	cin >> n;
    
	if (n == 1) {
	    cout << 0 << endl;
	    return 0;
	}

	vector<int64_t> ps;
	ps.emplace_back(2);
	for (int64_t i = 3; i <= n; i += 2)
	{
		bool f = true;
		for (auto &p : ps)
		{
			if (i < p * p)
			{
				break;
			}
			f &= i % p != 0;
		}
		if (f)
		{
			ps.emplace_back(i);
		}
	}

	int64_t ans = 0;
	for (auto &x : ps)
	{
		int64_t r = x * x;
		auto itr = lower_bound(ps.begin(), ps.end(), r - 2);
		if (itr != ps.end() && (*itr == r - 2))
		{
			ans++;
		}
	}
	ans *= 2;
	ans--;

	cout << ans << endl;

	return 0;
}
0