Submission #23859673


Source Code Expand

#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(n + 1, 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][prime_mask | pd[i]] += dp[i][prime_mask];
      }
      // skip
      dp[i + 1][prime_mask] += dp[i][prime_mask];
    }
  }

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

  return 0;
}

Submission Info

Submission Time
Task F - Coprime Present
User nika_skybytska
Language C++ (GCC 9.2.1)
Score 600
Code Size 1199 Byte
Status AC
Exec Time 472 ms
Memory 618052 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 36
Set Name Test Cases
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
Case Name Status Exec Time Memory
hand_01.txt AC 470 ms 617636 KiB
hand_02.txt AC 468 ms 618048 KiB
hand_03.txt AC 472 ms 617988 KiB
random_01.txt AC 42 ms 44116 KiB
random_02.txt AC 388 ms 511360 KiB
random_03.txt AC 469 ms 617900 KiB
random_04.txt AC 231 ms 298196 KiB
random_05.txt AC 320 ms 420984 KiB
random_06.txt AC 465 ms 617984 KiB
random_07.txt AC 115 ms 142480 KiB
random_08.txt AC 271 ms 355576 KiB
random_09.txt AC 469 ms 618048 KiB
random_10.txt AC 246 ms 322832 KiB
random_11.txt AC 398 ms 527696 KiB
random_12.txt AC 468 ms 618036 KiB
random_13.txt AC 86 ms 101656 KiB
random_14.txt AC 245 ms 322892 KiB
random_15.txt AC 466 ms 617956 KiB
random_16.txt AC 97 ms 117928 KiB
random_17.txt AC 315 ms 412768 KiB
random_18.txt AC 466 ms 618044 KiB
random_19.txt AC 199 ms 257376 KiB
random_20.txt AC 407 ms 544100 KiB
random_21.txt AC 464 ms 618000 KiB
random_22.txt AC 194 ms 248944 KiB
random_23.txt AC 393 ms 519516 KiB
random_24.txt AC 467 ms 618048 KiB
random_25.txt AC 134 ms 167124 KiB
random_26.txt AC 464 ms 617904 KiB
random_27.txt AC 464 ms 618052 KiB
random_28.txt AC 179 ms 224280 KiB
random_29.txt AC 364 ms 478564 KiB
random_30.txt AC 471 ms 617940 KiB
sample_01.txt AC 39 ms 43964 KiB
sample_02.txt AC 23 ms 27648 KiB
sample_03.txt AC 336 ms 437632 KiB