結果

問題 No.843 Triple Primes
ユーザー jjbnmhkjjbnmhk
提出日時 2020-05-11 18:40:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,936 bytes
コンパイル時間 1,724 ms
コンパイル使用メモリ 168,592 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2023-09-25 22:02:37
合計ジャッジ時間 3,726 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,832 KB
testcase_01 AC 8 ms
7,648 KB
testcase_02 AC 3 ms
6,752 KB
testcase_03 AC 3 ms
6,920 KB
testcase_04 AC 4 ms
6,712 KB
testcase_05 AC 4 ms
6,932 KB
testcase_06 AC 4 ms
6,740 KB
testcase_07 AC 7 ms
7,560 KB
testcase_08 AC 8 ms
7,704 KB
testcase_09 AC 8 ms
7,648 KB
testcase_10 AC 7 ms
7,552 KB
testcase_11 AC 8 ms
7,652 KB
testcase_12 AC 8 ms
7,580 KB
testcase_13 AC 8 ms
7,676 KB
testcase_14 AC 7 ms
7,560 KB
testcase_15 AC 8 ms
7,600 KB
testcase_16 AC 7 ms
7,844 KB
testcase_17 AC 4 ms
6,792 KB
testcase_18 AC 3 ms
6,828 KB
testcase_19 AC 3 ms
6,824 KB
testcase_20 AC 4 ms
7,244 KB
testcase_21 AC 4 ms
6,740 KB
testcase_22 AC 6 ms
7,384 KB
testcase_23 AC 6 ms
7,312 KB
testcase_24 AC 4 ms
7,288 KB
testcase_25 AC 4 ms
7,296 KB
testcase_26 AC 8 ms
7,564 KB
testcase_27 AC 4 ms
6,872 KB
testcase_28 AC 7 ms
7,556 KB
testcase_29 AC 5 ms
7,252 KB
testcase_30 AC 8 ms
7,564 KB
testcase_31 AC 4 ms
6,916 KB
testcase_32 AC 3 ms
6,716 KB
testcase_33 AC 4 ms
7,260 KB
testcase_34 AC 6 ms
7,336 KB
testcase_35 AC 8 ms
7,600 KB
testcase_36 AC 4 ms
7,320 KB
testcase_37 AC 6 ms
7,364 KB
testcase_38 AC 6 ms
7,360 KB
testcase_39 AC 8 ms
7,600 KB
testcase_40 AC 4 ms
6,808 KB
testcase_41 AC 3 ms
6,904 KB
testcase_42 AC 7 ms
7,584 KB
testcase_43 AC 8 ms
7,532 KB
権限があれば一括ダウンロードができます

ソースコード

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