提出 #23859752


ソースコード 拡げる

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

int main() {
  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

  int64_t a, b;
  cin >> a >> b;

  const int n = b - a + 1;
  vector<vector<bool>> g(n, vector<bool>(n));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (gcd(a + i, a + j) == 1) {
        g[i][j] = true;
      }
    }
  }

  // TODO: change to sieve
  const int k = 20;
  vector<int> p = { 2,  3,  5,  7, 11, 13, 17, 19, 23, 29,
                   31, 37, 41, 43, 47, 53, 59, 61, 67, 71};

  vector<int> pd(n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < k; ++j) {
      if ((a + i) % p[j] == 0) {
        pd[i] |= 1 << j;
      }
    }
  }

  vector<vector<int64_t>> dp(2, vector<int64_t>(1 << k));
  dp[0][0] = 1;

  for (int i = 0; i < n; ++i) {
    for (int prime_mask = 0; prime_mask < (1 << k); ++prime_mask) {
      // take
      if (!(prime_mask & pd[i])) {
        dp[(i + 1) & 1][prime_mask | pd[i]] += dp[i & 1][prime_mask];
      }
      // skip
      dp[(i + 1) & 1][prime_mask] += dp[i & 1][prime_mask];
    }
    dp[i & 1].assign(1 << k, 0);
  }

  cout << accumulate(dp[n & 1].begin(), dp[n & 1].end(), int64_t(0)) << "\n";

  return 0;
}

提出情報

提出日時
問題 F - Coprime Present
ユーザ nika_skybytska
言語 C++ (GCC 9.2.1)
得点 600
コード長 1257 Byte
結果 AC
実行時間 147 ms
メモリ 27748 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 3
AC × 36
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, hand_02.txt, hand_03.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
hand_01.txt AC 147 ms 27720 KiB
hand_02.txt AC 139 ms 27504 KiB
hand_03.txt AC 141 ms 27580 KiB
random_01.txt AC 36 ms 27632 KiB
random_02.txt AC 124 ms 27584 KiB
random_03.txt AC 140 ms 27660 KiB
random_04.txt AC 85 ms 27684 KiB
random_05.txt AC 103 ms 27564 KiB
random_06.txt AC 140 ms 27692 KiB
random_07.txt AC 48 ms 27720 KiB
random_08.txt AC 93 ms 27564 KiB
random_09.txt AC 142 ms 27632 KiB
random_10.txt AC 84 ms 27520 KiB
random_11.txt AC 120 ms 27624 KiB
random_12.txt AC 143 ms 27564 KiB
random_13.txt AC 44 ms 27632 KiB
random_14.txt AC 87 ms 27628 KiB
random_15.txt AC 137 ms 27708 KiB
random_16.txt AC 48 ms 27692 KiB
random_17.txt AC 104 ms 27516 KiB
random_18.txt AC 140 ms 27568 KiB
random_19.txt AC 74 ms 27568 KiB
random_20.txt AC 132 ms 27580 KiB
random_21.txt AC 140 ms 27712 KiB
random_22.txt AC 71 ms 27748 KiB
random_23.txt AC 124 ms 27744 KiB
random_24.txt AC 144 ms 27568 KiB
random_25.txt AC 56 ms 27744 KiB
random_26.txt AC 143 ms 27660 KiB
random_27.txt AC 143 ms 27744 KiB
random_28.txt AC 68 ms 27748 KiB
random_29.txt AC 113 ms 27656 KiB
random_30.txt AC 140 ms 27628 KiB
sample_01.txt AC 33 ms 27636 KiB
sample_02.txt AC 32 ms 27624 KiB
sample_03.txt AC 106 ms 27688 KiB