結果

問題 No.843 Triple Primes
ユーザー ateate
提出日時 2019-11-21 03:17:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,763 bytes
コンパイル時間 2,395 ms
コンパイル使用メモリ 203,064 KB
実行使用メモリ 5,632 KB
最終ジャッジ日時 2024-04-17 01:07:51
合計ジャッジ時間 59,846 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 TLE -
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 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 345 ms
5,376 KB
testcase_21 AC 109 ms
5,376 KB
testcase_22 AC 1,017 ms
5,376 KB
testcase_23 AC 1,241 ms
5,376 KB
testcase_24 AC 369 ms
5,376 KB
testcase_25 AC 250 ms
5,376 KB
testcase_26 TLE -
testcase_27 AC 28 ms
5,376 KB
testcase_28 TLE -
testcase_29 AC 391 ms
5,376 KB
testcase_30 TLE -
testcase_31 AC 52 ms
5,376 KB
testcase_32 AC 22 ms
5,376 KB
testcase_33 AC 471 ms
5,376 KB
testcase_34 AC 893 ms
5,376 KB
testcase_35 TLE -
testcase_36 AC 194 ms
5,376 KB
testcase_37 AC 1,936 ms
5,376 KB
testcase_38 AC 1,407 ms
5,376 KB
testcase_39 TLE -
testcase_40 AC 3 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 TLE -
testcase_43 TLE -
権限があれば一括ダウンロードができます

ソースコード

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>(*--a.end()+*----a.end()))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