結果
| 問題 | No.843 Triple Primes | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-02-09 16:41:18 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 4 ms / 2,000 ms | 
| コード長 | 492 bytes | 
| コンパイル時間 | 1,708 ms | 
| コンパイル使用メモリ | 169,536 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-01 06:03:21 | 
| 合計ジャッジ時間 | 2,726 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 42 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n;cin >> n;
    vector<bool> p(n+1,true);
    p[0]=false,p[1]=false;
    for(int i=2;i*i<=n;i++){
        if(p[i]){
            for(int j=2;j*i<=n;j++){
                p[i*j]=false;
            }
        }
    }
    int ans=0;
    for(ll i=2;i*i-2<=n;i++){
        if(p[i]&&p[i*i-2]){
            ans++;
            if(i!=2){
                ans++;
            }
        }
    }
    cout << ans << endl;
}
            
            
            
        