結果

問題 No.843 Triple Primes
ユーザー ateate
提出日時 2019-11-21 03:13:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,741 bytes
コンパイル時間 2,294 ms
コンパイル使用メモリ 202,652 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-04-17 00:58:51
合計ジャッジ時間 5,747 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
void dump(){cout<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cout<<h<<", ";dump(forward<Ts>(t)...);}
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

void solve1();void solve2();
int main(){
  solve1();
  return 0;
}

void solve1(){

  ll n;
  cin>>n;

  auto prime_enumration = [](ll n){
    vector<bool> a(n+1,true);
    for(ll p=2;p<=n;++p){
      if(!a[p])continue;
      ll x=p+p;
      while(x<=n){a[x]=false;x+=p;}
    }
    set<ll> primes;
    for(ll p=2;p<=n;++p){
      if(a[p])primes.emplace(p);
    }
    return primes;
  };
  auto square_enum = [](set<ll>const& a,ll n){
    set<ll> suq;
    for(auto const& v:a){
      //if(v*v>n)break;
      suq.insert(v*v);
    }
    return suq;
  };

  auto a = prime_enumration(n);
  auto b = square_enum(a,n);
  
  ll ans = 0;
  for(auto rr:b){
    for(ll p=0;p<=rr;++p){
      ll q=rr-p;
      if(a.find(p)==a.end())continue;
      if(a.find(q)==a.end())continue;
      ans++;
    }
  }
  cout<<(ans)<<endl;

}
0