結果

問題 No.1653 Squarefree
ユーザー risujirohrisujiroh
提出日時 2021-08-20 22:42:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 849 ms / 2,000 ms
コード長 1,254 bytes
コンパイル時間 2,158 ms
コンパイル使用メモリ 207,132 KB
実行使用メモリ 94,480 KB
最終ジャッジ日時 2023-08-04 11:32:24
合計ジャッジ時間 25,020 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 771 ms
94,480 KB
testcase_01 AC 10 ms
7,636 KB
testcase_02 AC 9 ms
7,492 KB
testcase_03 AC 10 ms
7,588 KB
testcase_04 AC 9 ms
7,524 KB
testcase_05 AC 8 ms
7,524 KB
testcase_06 AC 9 ms
7,592 KB
testcase_07 AC 9 ms
7,588 KB
testcase_08 AC 9 ms
7,636 KB
testcase_09 AC 10 ms
7,564 KB
testcase_10 AC 10 ms
7,564 KB
testcase_11 AC 717 ms
92,904 KB
testcase_12 AC 726 ms
92,732 KB
testcase_13 AC 769 ms
93,932 KB
testcase_14 AC 774 ms
93,668 KB
testcase_15 AC 846 ms
94,412 KB
testcase_16 AC 796 ms
93,860 KB
testcase_17 AC 802 ms
93,968 KB
testcase_18 AC 801 ms
94,136 KB
testcase_19 AC 768 ms
93,968 KB
testcase_20 AC 783 ms
94,416 KB
testcase_21 AC 793 ms
94,384 KB
testcase_22 AC 763 ms
94,452 KB
testcase_23 AC 756 ms
93,516 KB
testcase_24 AC 747 ms
93,664 KB
testcase_25 AC 821 ms
94,224 KB
testcase_26 AC 845 ms
93,604 KB
testcase_27 AC 788 ms
94,172 KB
testcase_28 AC 753 ms
93,868 KB
testcase_29 AC 781 ms
94,192 KB
testcase_30 AC 849 ms
93,420 KB
testcase_31 AC 779 ms
94,120 KB
testcase_32 AC 775 ms
94,184 KB
testcase_33 AC 792 ms
93,912 KB
testcase_34 AC 794 ms
94,196 KB
testcase_35 AC 843 ms
94,148 KB
testcase_36 AC 9 ms
7,568 KB
testcase_37 AC 9 ms
7,496 KB
testcase_38 AC 9 ms
7,764 KB
testcase_39 AC 9 ms
7,544 KB
testcase_40 AC 10 ms
7,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

namespace sieve {

std::vector<int> primes, lpf;
void init(int n) {
  if (n < int(std::size(lpf))) return;
  if (n < 2 * int(std::size(lpf))) n = 2 * std::size(lpf);
  lpf.resize(n + 1, -1);
  for (int d = 2; d <= n; ++d) {
    if (lpf[d] == -1) lpf[d] = d, primes.push_back(d);
    for (int p : primes) {
      if (p * d > n or p > lpf[d]) break;
      lpf[p * d] = p;
    }
  }
}

}  // namespace sieve

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int64_t l, r;
  cin >> l >> r;
  sieve::init(1e6);

  vector<int64_t> num(r - l + 1);
  iota(begin(num), end(num), l);

  vector<vector<int64_t>> factor(r - l + 1);

  for (int p : sieve::primes) {
    for (auto i = r / p * p; i >= l; i -= p) {
      while (num[i - l] % p == 0) {
        num[i - l] /= p;
        factor[i - l].push_back(p);
      }
    }
  }

  int ans = 0;
  for (auto i = l; i <= r; ++i) {
    if (adjacent_find(begin(factor[i - l]), end(factor[i - l])) != end(factor[i - l])) {
      continue;
    }

    if (num[i - l] > 1) {
      if (int64_t t = sqrtl(num[i - l]); t * t == num[i - l]) {
        continue;
      }
    }

    ++ans;
  }
  cout << ans << '\n';
}
0