結果

問題 No.843 Triple Primes
ユーザー ateate
提出日時 2019-11-21 03:24:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,494 ms / 2,000 ms
コード長 1,959 bytes
コンパイル時間 2,532 ms
コンパイル使用メモリ 207,940 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 01:21:24
合計ジャッジ時間 33,726 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1,454 ms
5,376 KB
testcase_02 AC 5 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 7 ms
5,376 KB
testcase_05 AC 5 ms
5,376 KB
testcase_06 AC 8 ms
5,376 KB
testcase_07 AC 1,083 ms
5,376 KB
testcase_08 AC 1,178 ms
5,376 KB
testcase_09 AC 1,468 ms
5,376 KB
testcase_10 AC 1,137 ms
5,376 KB
testcase_11 AC 1,282 ms
5,376 KB
testcase_12 AC 1,401 ms
5,376 KB
testcase_13 AC 1,321 ms
5,376 KB
testcase_14 AC 1,346 ms
5,376 KB
testcase_15 AC 1,098 ms
5,376 KB
testcase_16 AC 1,127 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 213 ms
5,376 KB
testcase_21 AC 91 ms
5,376 KB
testcase_22 AC 606 ms
5,376 KB
testcase_23 AC 639 ms
5,376 KB
testcase_24 AC 230 ms
5,376 KB
testcase_25 AC 166 ms
5,376 KB
testcase_26 AC 1,442 ms
5,376 KB
testcase_27 AC 26 ms
5,376 KB
testcase_28 AC 1,356 ms
5,376 KB
testcase_29 AC 248 ms
5,376 KB
testcase_30 AC 1,408 ms
5,376 KB
testcase_31 AC 48 ms
5,376 KB
testcase_32 AC 20 ms
5,376 KB
testcase_33 AC 294 ms
5,376 KB
testcase_34 AC 533 ms
5,376 KB
testcase_35 AC 1,494 ms
5,376 KB
testcase_36 AC 137 ms
5,376 KB
testcase_37 AC 1,125 ms
5,376 KB
testcase_38 AC 736 ms
5,376 KB
testcase_39 AC 1,375 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 1,170 ms
5,376 KB
testcase_43 AC 1,262 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;
  if(n==1){cout<<0<<endl;return;}
  if(n==2){cout<<1<<endl;return;}

  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