結果

問題 No.843 Triple Primes
ユーザー pockynypockyny
提出日時 2019-06-28 22:51:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 599 bytes
コンパイル時間 720 ms
コンパイル使用メモリ 82,988 KB
実行使用メモリ 6,112 KB
最終ジャッジ日時 2023-10-19 17:50:01
合計ジャッジ時間 2,292 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 14 ms
6,112 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 2 ms
4,348 KB
testcase_07 AC 12 ms
5,816 KB
testcase_08 AC 13 ms
5,852 KB
testcase_09 AC 15 ms
6,100 KB
testcase_10 AC 13 ms
5,828 KB
testcase_11 AC 14 ms
5,976 KB
testcase_12 AC 14 ms
6,048 KB
testcase_13 AC 14 ms
5,988 KB
testcase_14 AC 14 ms
5,988 KB
testcase_15 AC 12 ms
5,820 KB
testcase_16 AC 13 ms
5,828 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 5 ms
4,400 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 9 ms
5,080 KB
testcase_23 AC 9 ms
5,136 KB
testcase_24 AC 5 ms
4,436 KB
testcase_25 AC 4 ms
4,348 KB
testcase_26 AC 14 ms
6,096 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 14 ms
6,008 KB
testcase_29 AC 5 ms
4,484 KB
testcase_30 AC 14 ms
6,064 KB
testcase_31 AC 3 ms
4,348 KB
testcase_32 AC 3 ms
4,348 KB
testcase_33 AC 5 ms
4,560 KB
testcase_34 AC 8 ms
4,976 KB
testcase_35 AC 14 ms
6,104 KB
testcase_36 AC 4 ms
4,348 KB
testcase_37 AC 11 ms
5,588 KB
testcase_38 AC 10 ms
5,308 KB
testcase_39 AC 14 ms
6,028 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 12 ms
5,840 KB
testcase_43 AC 13 ms
5,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
using namespace std;
vector<long long> p;
set<long long> s;
bool used[500010];
void prime(int n){
	int i,j;
	for(i=2;i<=n;i++){
		used[i] = true;
	}
	for(i=2;i<=n;i++){
		if(!used[i]) continue;
		for(j=2*i;j<=n;j+=i){
			used[j] = false;
		}
	}
}

int main(){
	int i,n,cnt = 1;
	cin >> n;
	if(n==1){
		cout << 0 << endl;
		return 0;
	}
	prime(n);
	for(i=3;i<=n;i++){
		if(used[i]){
			p.push_back(i);
			s.insert(i);
		}
	}
	for(i=0;i<p.size();i++){
		if(p[i]*p[i] - 2>n) break;
		if(s.count(p[i]*p[i] - 2)) cnt += 2;
	}
	cout << cnt << endl;
}
	
0