結果

問題 No.843 Triple Primes
ユーザー kurarrrkurarrr
提出日時 2019-07-19 01:06:03
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 2,861 bytes
コンパイル時間 2,183 ms
コンパイル使用メモリ 206,708 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 18:02:40
合計ジャッジ時間 3,662 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}
void solve();
int main(void) {
  std::cout << std::fixed << std::setprecision(15);
  solve();
	return 0;
}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<Pl>;
using vvp = vector<vp>;

const int INF = 1<<29;
const long long LINF=1LL<<59;

// 素数
vector<ll> primes(ll n, vector<bool>& is_prime) {
  is_prime[0] = is_prime[1] = false;
  vector<ll> res;
  for(ll i = 2; i <= n; i++){
    if(!is_prime[i]) continue;
    for(ll j = 2; j*i <= n; j++) is_prime[j*i] = false;
    res.push_back(i);
  }
  return res;
}

void solve(){
  ll N; cin >> N ;
  vector<bool> is_prime(N+1,true);
  auto pr = primes(N, is_prime);
  ll ans = 0;
  for(auto r:pr){
    if(r*r>2*N) continue;
    // r ~ sqrt(N)
    ll d = r*r;
    for(auto p:pr){
      if(d-p>N) continue;
      if(p<=d-p && is_prime[d-p]){
        ans += (2*p==d ? 1 : 2);
      }
    }
  }
  cout << ans << endl;
}
0