結果

問題 No.843 Triple Primes
ユーザー 👑 CleyL
提出日時 2022-04-23 11:28:27
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 610 bytes
コンパイル時間 745 ms
コンパイル使用メモリ 74,944 KB
最終ジャッジ日時 2025-01-28 21:04:48
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

struct SieveEratos{
  vector<bool> t;
  vector<int> primes;
  SieveEratos(int n):t(n+1,true){
    t[0] = t[1] = false;
    for(int i = 2; n >= i; i++){
      if(t[i]){
        primes.emplace_back(i);
        for(int j = i+i; n >= j; j+=i){
          t[j] = false;
        }
      }
    }
  }
  bool operator[](int x){return t[x];}
};
int main(){
  long long n;cin>>n;
  SieveEratos A(n+1);
  int ans = 0;
  for(int i = 0; n+2 >= A.primes[i]*A.primes[i]; i++){
    if(A[A.primes[i]*A.primes[i]-2])ans+=2;
    if(!i)ans--;
  }
  cout << ans << endl;
}
0