結果
| 問題 | No.843 Triple Primes | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-06-28 21:45:19 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 68 ms / 2,000 ms | 
| コード長 | 1,233 bytes | 
| コンパイル時間 | 756 ms | 
| コンパイル使用メモリ | 75,952 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-09-19 13:59:16 | 
| 合計ジャッジ時間 | 3,103 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 42 | 
ソースコード
#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;
}
            
            
            
        