結果

問題 No.843 Triple Primes
ユーザー okok
提出日時 2019-06-28 21:45:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,233 bytes
コンパイル時間 750 ms
コンパイル使用メモリ 75,980 KB
実行使用メモリ 4,528 KB
最終ジャッジ日時 2023-10-19 17:40:28
合計ジャッジ時間 3,386 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 70 ms
4,528 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 53 ms
4,348 KB
testcase_08 AC 59 ms
4,408 KB
testcase_09 AC 70 ms
4,520 KB
testcase_10 AC 55 ms
4,364 KB
testcase_11 AC 63 ms
4,448 KB
testcase_12 AC 68 ms
4,500 KB
testcase_13 AC 65 ms
4,472 KB
testcase_14 AC 66 ms
4,476 KB
testcase_15 AC 54 ms
4,348 KB
testcase_16 AC 55 ms
4,360 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 13 ms
4,348 KB
testcase_21 AC 6 ms
4,348 KB
testcase_22 AC 32 ms
4,348 KB
testcase_23 AC 34 ms
4,348 KB
testcase_24 AC 14 ms
4,348 KB
testcase_25 AC 10 ms
4,348 KB
testcase_26 AC 69 ms
4,520 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 67 ms
4,484 KB
testcase_29 AC 15 ms
4,348 KB
testcase_30 AC 68 ms
4,504 KB
testcase_31 AC 4 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 17 ms
4,348 KB
testcase_34 AC 29 ms
4,348 KB
testcase_35 AC 70 ms
4,524 KB
testcase_36 AC 9 ms
4,348 KB
testcase_37 AC 50 ms
4,348 KB
testcase_38 AC 40 ms
4,348 KB
testcase_39 AC 67 ms
4,492 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 1 ms
4,348 KB
testcase_42 AC 57 ms
4,384 KB
testcase_43 AC 63 ms
4,444 KB
権限があれば一括ダウンロードができます

ソースコード

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  1010000

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*2+10);
	
	for(int i = 1; i*i <= 2*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(j > N || k > N) continue;
			if(PN[j] == false && PN[k] == false) count++;
		}
	}
	
	cout<<count<<endl;
	
	return 0;
}
0