結果

問題 No.732 3PrimeCounting
ユーザー HaraTakashiHaraTakashi
提出日時 2021-12-31 21:36:01
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 415 ms / 3,000 ms
コード長 2,339 bytes
コンパイル時間 2,036 ms
コンパイル使用メモリ 198,612 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 09:25:03
合計ジャッジ時間 11,927 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,812 KB
testcase_01 AC 5 ms
6,940 KB
testcase_02 AC 5 ms
6,940 KB
testcase_03 AC 6 ms
6,944 KB
testcase_04 AC 6 ms
6,944 KB
testcase_05 AC 6 ms
6,940 KB
testcase_06 AC 5 ms
6,944 KB
testcase_07 AC 6 ms
6,944 KB
testcase_08 AC 5 ms
6,940 KB
testcase_09 AC 6 ms
6,944 KB
testcase_10 AC 6 ms
6,944 KB
testcase_11 AC 6 ms
6,944 KB
testcase_12 AC 6 ms
6,940 KB
testcase_13 AC 6 ms
6,940 KB
testcase_14 AC 6 ms
6,944 KB
testcase_15 AC 6 ms
6,944 KB
testcase_16 AC 6 ms
6,940 KB
testcase_17 AC 6 ms
6,940 KB
testcase_18 AC 6 ms
6,940 KB
testcase_19 AC 6 ms
6,944 KB
testcase_20 AC 10 ms
6,944 KB
testcase_21 AC 20 ms
6,940 KB
testcase_22 AC 21 ms
6,944 KB
testcase_23 AC 8 ms
6,944 KB
testcase_24 AC 8 ms
6,940 KB
testcase_25 AC 33 ms
6,940 KB
testcase_26 AC 26 ms
6,940 KB
testcase_27 AC 12 ms
6,940 KB
testcase_28 AC 12 ms
6,940 KB
testcase_29 AC 19 ms
6,940 KB
testcase_30 AC 18 ms
6,940 KB
testcase_31 AC 22 ms
6,940 KB
testcase_32 AC 28 ms
6,940 KB
testcase_33 AC 29 ms
6,940 KB
testcase_34 AC 27 ms
6,940 KB
testcase_35 AC 24 ms
6,944 KB
testcase_36 AC 23 ms
6,944 KB
testcase_37 AC 9 ms
6,944 KB
testcase_38 AC 8 ms
6,944 KB
testcase_39 AC 24 ms
6,940 KB
testcase_40 AC 24 ms
6,944 KB
testcase_41 AC 24 ms
6,944 KB
testcase_42 AC 23 ms
6,940 KB
testcase_43 AC 19 ms
6,940 KB
testcase_44 AC 20 ms
6,944 KB
testcase_45 AC 13 ms
6,944 KB
testcase_46 AC 12 ms
6,944 KB
testcase_47 AC 14 ms
6,940 KB
testcase_48 AC 33 ms
6,940 KB
testcase_49 AC 34 ms
6,944 KB
testcase_50 AC 22 ms
6,940 KB
testcase_51 AC 20 ms
6,944 KB
testcase_52 AC 12 ms
6,940 KB
testcase_53 AC 58 ms
6,940 KB
testcase_54 AC 246 ms
6,940 KB
testcase_55 AC 225 ms
6,944 KB
testcase_56 AC 232 ms
6,940 KB
testcase_57 AC 104 ms
6,940 KB
testcase_58 AC 104 ms
6,944 KB
testcase_59 AC 60 ms
6,940 KB
testcase_60 AC 131 ms
6,940 KB
testcase_61 AC 122 ms
6,944 KB
testcase_62 AC 272 ms
6,944 KB
testcase_63 AC 179 ms
6,944 KB
testcase_64 AC 151 ms
6,944 KB
testcase_65 AC 143 ms
6,944 KB
testcase_66 AC 7 ms
6,944 KB
testcase_67 AC 7 ms
6,944 KB
testcase_68 AC 240 ms
6,940 KB
testcase_69 AC 256 ms
6,940 KB
testcase_70 AC 240 ms
6,940 KB
testcase_71 AC 240 ms
6,944 KB
testcase_72 AC 166 ms
6,944 KB
testcase_73 AC 343 ms
6,940 KB
testcase_74 AC 338 ms
6,944 KB
testcase_75 AC 33 ms
6,944 KB
testcase_76 AC 247 ms
6,944 KB
testcase_77 AC 113 ms
6,940 KB
testcase_78 AC 312 ms
6,944 KB
testcase_79 AC 266 ms
6,944 KB
testcase_80 AC 285 ms
6,944 KB
testcase_81 AC 251 ms
6,940 KB
testcase_82 AC 11 ms
6,940 KB
testcase_83 AC 108 ms
6,944 KB
testcase_84 AC 117 ms
6,944 KB
testcase_85 AC 204 ms
6,940 KB
testcase_86 AC 298 ms
6,944 KB
testcase_87 AC 415 ms
6,940 KB
testcase_88 AC 393 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;
#define al(a) a.begin(), a.end()
#define ral(a) a.rbegin(), a.rend()
#define sz(a) (int)a.size()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define db(a, b) cout << #a << ": " << a << " " << #b << ": " << b << endl;

const int MX = 330005;
vector<int> primes;
vector<bool> is_prime(MX, true);
void sieve() {
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= MX; ++i) {
    if (is_prime[i]) {
      primes.push_back(i);
      for (int j = 2 * i; j <= MX; j += i) { is_prime[j] = false; }
    }
  }
}

vector<int> cnt(MX);
int main() {
  int n;
  cin >> n;

  sieve();
  ll ans = 0;
  //   for (int c = 2; primes[c] <= n; ++c) {
  //     int b = c - 1;
  //     rep(a, b) cnt[primes[a] + primes[b]]++;
  //     for (int y = c + 1; primes[y] <= primes[c] * 3; ++y) {
  //       ans += cnt[primes[y] - primes[c]];
  //     }
  //   }
  rrep(i, sz(primes)) {
    int c = primes[i];
    if (c > n) break;
    int b = primes[i - 1];
    rep(j, i - 1) {
      int a = primes[j];
      cnt[a + b]++;
    }
    rep(j, sz(primes)) {
      int sum = primes[j];
      if (sum - c >= 0) ans += cnt[sum - c];
    }
  }
  cout << ans << endl;
  return 0;
}
// int main() {
//   int n;
//   cin >> n;

//   set<int> s;
//   const int MAX_N = 300005;
//   bool is_prime[MAX_N];
//   for (int i = 0; i <= n; ++i) { is_prime[i] = true; }
//   is_prime[0] = is_prime[1] = false;
//   for (int i = 2; i <= n; ++i) {
//     if (is_prime[i]) {
//       s.insert(i);
//       for (int j = 2 * i; j <= n; j += i) { is_prime[j] = false; }
//     }
//   }
//   map<int, int> mp;
//   mp[0] = 1;
//   rep(ri, 3) {
//     map<int, int> pre;
//     swap(pre, mp);
//     for (auto [x, val] : pre) {
//       for (auto p : s) {
//         if (n < p) break;
//         mp[x + p] += val;
//       }
//     }
//   }
//   ll ans = 0;
//   for (auto [x, val] : mp) {
//     if (s.count(x)) ans += val;
//   }
//   cout << ans << endl;
//   //   map<P, int> mp;
//   //   mp[P(1,0)] = 1;
//   //     for (auto [x,val] : mp) {
//   //         auto &[]
//   //       for (auto p : s) {

//   //       }
//   //     }
//   return 0;
// }
0