結果

問題 No.843 Triple Primes
ユーザー ateate
提出日時 2019-11-21 03:22:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,891 bytes
コンパイル時間 2,171 ms
コンパイル使用メモリ 208,900 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 01:15:15
合計ジャッジ時間 28,354 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1,241 ms
5,376 KB
testcase_02 AC 5 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 6 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 7 ms
5,376 KB
testcase_07 AC 954 ms
5,376 KB
testcase_08 AC 1,028 ms
5,376 KB
testcase_09 AC 1,258 ms
5,376 KB
testcase_10 AC 986 ms
5,376 KB
testcase_11 AC 1,110 ms
5,376 KB
testcase_12 AC 1,209 ms
5,376 KB
testcase_13 AC 1,174 ms
5,376 KB
testcase_14 AC 1,174 ms
5,376 KB
testcase_15 AC 967 ms
5,376 KB
testcase_16 AC 978 ms
5,376 KB
testcase_17 RE -
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 192 ms
5,376 KB
testcase_21 AC 79 ms
5,376 KB
testcase_22 AC 528 ms
5,376 KB
testcase_23 AC 559 ms
5,376 KB
testcase_24 AC 201 ms
5,376 KB
testcase_25 AC 143 ms
5,376 KB
testcase_26 AC 1,270 ms
6,944 KB
testcase_27 AC 23 ms
5,376 KB
testcase_28 AC 1,199 ms
5,376 KB
testcase_29 AC 214 ms
5,376 KB
testcase_30 AC 1,218 ms
5,376 KB
testcase_31 AC 41 ms
5,376 KB
testcase_32 AC 18 ms
5,376 KB
testcase_33 AC 277 ms
5,376 KB
testcase_34 AC 469 ms
5,376 KB
testcase_35 AC 1,301 ms
5,376 KB
testcase_36 AC 120 ms
5,376 KB
testcase_37 AC 857 ms
5,376 KB
testcase_38 AC 687 ms
5,376 KB
testcase_39 AC 1,229 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 RE -
testcase_42 AC 1,038 ms
5,376 KB
testcase_43 AC 1,118 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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;}
    }
    vector<ll> primes;
    for(ll p=2;p<=n;++p){
      if(a[p])primes.emplace_back(p);
    }
    sort(primes.begin(),primes.end());
    return primes;
  };
  auto square_enum = [](vector<ll>const& a,ll n,ll limit){
    set<ll> suq;
    for(auto const& v:a){
      if(v*v>limit)break;
      suq.insert(v*v);
    }
    return suq;
  };

  auto a = prime_enumration(n);
  ll m = a.size();
  ll limit = a[m-1]+a[m-2];
  auto b = square_enum(a,n,limit);
  
  ll ans = 0;
  for(auto rr:b){
    for(ll p=0;p<=rr;++p){
      ll q=rr-p;
      if(*lower_bound(a.begin(),a.end(),p)!=p)continue;
      if(*lower_bound(a.begin(),a.end(),q)!=q)continue;
      ans++;
    }
  }
  cout<<(ans)<<endl;

}
0