結果

問題 No.843 Triple Primes
ユーザー chocoruskchocorusk
提出日時 2019-06-28 21:30:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 1,135 bytes
コンパイル時間 777 ms
コンパイル使用メモリ 102,352 KB
実行使用メモリ 8,356 KB
最終ジャッジ日時 2023-10-19 17:29:25
合計ジャッジ時間 2,487 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int MAX=600010;
vector<ll> prime;
bool isprime[MAX];
void sieve(){
	for(ll i=3; i<MAX; i+=2){
		isprime[i]=1;
	}
	isprime[2]=1;
	prime.push_back(2);
	for(ll i=3; i<MAX; i++){
		if(isprime[i]){
			prime.push_back(i);
			for(ll j=2*i; j<MAX; j+=i){
				isprime[j]=0;
			}
		}
	}
	return;
}
int main()
{
    int n; cin>>n;
    sieve();
    if(n==1){
        cout<<0<<endl; return 0;
    }
    if(n==2){
        cout<<1<<endl; return 0;
    }
    int sq[1000010]={};
    for(int i=1; i*i<=2*n; i++){
        sq[i*i]=i;
    }
    int ans=1;
    for(int i=1; prime[i]<=n; i++){
        int x=sq[2+prime[i]];
        if(x>0 && isprime[x]) ans+=2;
    }
    cout<<ans<<endl;
    return 0;
}
0