結果

問題 No.843 Triple Primes
ユーザー soysoy
提出日時 2019-08-13 18:36:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 896 bytes
コンパイル時間 779 ms
コンパイル使用メモリ 86,696 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 18:05:44
合計ジャッジ時間 2,634 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 33 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 26 ms
4,348 KB
testcase_08 AC 28 ms
4,348 KB
testcase_09 AC 33 ms
4,348 KB
testcase_10 AC 27 ms
4,348 KB
testcase_11 AC 30 ms
4,348 KB
testcase_12 AC 32 ms
4,348 KB
testcase_13 AC 31 ms
4,348 KB
testcase_14 AC 31 ms
4,348 KB
testcase_15 AC 26 ms
4,348 KB
testcase_16 AC 27 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 8 ms
4,348 KB
testcase_21 AC 5 ms
4,348 KB
testcase_22 AC 16 ms
4,348 KB
testcase_23 AC 17 ms
4,348 KB
testcase_24 AC 9 ms
4,348 KB
testcase_25 AC 7 ms
4,348 KB
testcase_26 AC 33 ms
4,348 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 32 ms
4,348 KB
testcase_29 AC 9 ms
4,348 KB
testcase_30 AC 33 ms
4,348 KB
testcase_31 AC 4 ms
4,348 KB
testcase_32 AC 3 ms
4,348 KB
testcase_33 AC 10 ms
4,348 KB
testcase_34 AC 15 ms
4,348 KB
testcase_35 AC 33 ms
4,348 KB
testcase_36 AC 6 ms
4,348 KB
testcase_37 AC 24 ms
4,348 KB
testcase_38 AC 20 ms
4,348 KB
testcase_39 AC 31 ms
4,348 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 27 ms
4,348 KB
testcase_43 AC 30 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<math.h>
using namespace std;

vector<int> prime;
int ans = 0;

int main(void) {
	void checkcount(int);
	int n,check=1;
	cin >> n;
	if (n < 2) {
		cout << 0;
		return 0;
	}
	prime.push_back(2);
		for (int i = 3; i <=n; i += 2) {
			check = 1;
			for (int j = 0; j < size(prime); j++) {
				if (i % prime[j] == 0) {
					check = 0;
					break;
				}
				if (prime[j] > sqrt(i)) break;
			}
			if (check) prime.push_back(i);
	    }
	for (int i = 0;i<size(prime); i++) {
		if (prime[i] * prime[i] > prime[size(prime) - 1]+2) break;
		checkcount(prime[i]);
	}

	cout << ans<<endl;
}

void checkcount(int r) {
	int left = -1, right = size(prime)-1,center;
	while (right - left != 1) {
		center = (left + right) / 2;
		if (prime[center] + 2 < r * r) left = center;
		else right = center;
	}
	if (prime[right] + 2 == r * r)
		ans += 1 + (prime[right] != 2);
}
0