結果

問題 No.843 Triple Primes
ユーザー pockynypockyny
提出日時 2019-06-28 21:40:02
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 595 bytes
コンパイル時間 873 ms
コンパイル使用メモリ 82,400 KB
実行使用メモリ 5,968 KB
最終ジャッジ日時 2023-09-14 21:44:34
合計ジャッジ時間 2,961 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 14 ms
5,832 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 12 ms
5,636 KB
testcase_08 AC 14 ms
5,512 KB
testcase_09 AC 15 ms
5,912 KB
testcase_10 AC 13 ms
5,420 KB
testcase_11 AC 13 ms
5,636 KB
testcase_12 AC 14 ms
5,688 KB
testcase_13 AC 14 ms
5,792 KB
testcase_14 AC 14 ms
5,700 KB
testcase_15 AC 12 ms
5,484 KB
testcase_16 AC 12 ms
5,544 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 9 ms
4,720 KB
testcase_23 AC 8 ms
4,940 KB
testcase_24 AC 5 ms
4,376 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 14 ms
5,740 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 14 ms
5,876 KB
testcase_29 AC 5 ms
4,376 KB
testcase_30 AC 14 ms
5,688 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 5 ms
4,464 KB
testcase_34 AC 8 ms
4,672 KB
testcase_35 AC 15 ms
5,968 KB
testcase_36 AC 4 ms
4,380 KB
testcase_37 AC 12 ms
5,420 KB
testcase_38 AC 10 ms
5,116 KB
testcase_39 AC 14 ms
5,728 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 WA -
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

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]>n) break;
		if(s.count(p[i]*p[i] - 2)) cnt += 2;
	}
	cout << cnt << endl;
}
	
0