結果

問題 No.843 Triple Primes
ユーザー jjbnmhk
提出日時 2020-05-11 18:40:47
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,936 bytes
コンパイル時間 1,634 ms
コンパイル使用メモリ 171,116 KB
実行使用メモリ 7,936 KB
最終ジャッジ日時 2024-07-18 17:43:36
合計ジャッジ時間 3,152 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
ll n;
vll a(0);
vll arr(5*100000+3);
void Eratosthenes(){
	for(ll i = 2; i <= n; i++){
		arr[i] = 1;
	}
	for(int i = 2; i <=sqrt(n); i++){
		if(arr[i]){
			for(int j = 0; i * (j + 2) <= n; j++){
				arr[i *(j + 2)] = 0;
			}
		}
	}
	for(int i = 2; i <= n; i++){
		if(arr[i]){
			a.pb(i);
		}
	}
}
int main(){
  cin>>n;
  Eratosthenes();
  ll ans=0;
  if(n>=2){
    ans++;
    rep(i,sz(a)){
      if(i==0) continue;
      else{
        if(a[i]*a[i]-2<=n&&arr[a[i]*a[i]-2]) ans+=2;
      }
    }
    COUT(ans);
  }
  else COUT(0);
}
0