結果

問題 No.843 Triple Primes
ユーザー okok
提出日時 2019-06-28 21:39:02
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,194 bytes
コンパイル時間 811 ms
コンパイル使用メモリ 74,848 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 21:43:34
合計ジャッジ時間 3,337 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 40 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 30 ms
4,380 KB
testcase_08 AC 35 ms
4,380 KB
testcase_09 AC 40 ms
4,380 KB
testcase_10 AC 32 ms
4,380 KB
testcase_11 AC 37 ms
4,376 KB
testcase_12 AC 39 ms
4,376 KB
testcase_13 AC 38 ms
4,380 KB
testcase_14 AC 38 ms
4,380 KB
testcase_15 AC 30 ms
4,380 KB
testcase_16 AC 32 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 WA -
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 8 ms
4,376 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 19 ms
4,380 KB
testcase_23 AC 19 ms
4,376 KB
testcase_24 AC 9 ms
4,380 KB
testcase_25 AC 6 ms
4,380 KB
testcase_26 AC 40 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 39 ms
4,380 KB
testcase_29 AC 9 ms
4,376 KB
testcase_30 AC 39 ms
4,376 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 10 ms
4,376 KB
testcase_34 AC 17 ms
4,376 KB
testcase_35 AC 40 ms
4,376 KB
testcase_36 AC 6 ms
4,376 KB
testcase_37 AC 29 ms
4,380 KB
testcase_38 AC 23 ms
4,376 KB
testcase_39 AC 39 ms
4,376 KB
testcase_40 WA -
testcase_41 AC 1 ms
4,376 KB
testcase_42 WA -
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define MAX

#define MAX_PN  510000

bool PN[MAX_PN+2];

void huga(int t, int x){
	if(PN[t]) return;
	for(int i = t*t; i <= x; i+=t)
		PN[i] = true;
}

void Sieve_of_Eratosthenes(int x){
	PN[0]=PN[1]=PN[4]=true;
	for(int i = 6; (i-1)*(i-1) <= x; i+=6)
		huga(i-1,x),huga(i+1,x);
	for(int i = 6; i <= x; i+=6)
		PN[i]=PN[i+2]=PN[i+3]=PN[i+4]=true;
}


signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N;
	int count = 0;
	vector<int> square;
	cin>>N;
	
	Sieve_of_Eratosthenes(N+10);
	
	for(int i = 1; i*i <= N; i++){
		if(PN[i] == false) square.push_back(i*i);
	}
	
	for(int i = 0; i < square.size(); i++){
		for(int j = 2; j < square[i]; j++){
			int k = square[i] - j;
			
			if(PN[j] == false && PN[k] == false) count++;
		}
	}
	
	cout<<count<<endl;
	
	return 0;
}
0