This documentation is automatically generated by competitive-verifier/competitive-verifier
// competitive-verifier: STANDALONE
// Source: https://atcoder.jp/contests/abc227/tasks/abc227_g
#include <iostream>
#include "atcoder/modint.hpp"
#include "tools/assert_that.hpp"
#include "tools/linear_sieve.hpp"
#include "tools/segmented_sieve.hpp"
#include "tools/unordered_map.hpp"
using ll = long long;
using mint = atcoder::modint998244353;
mint solve(const ll N, const int K) {
tools::unordered_map<ll, ll> nCk;
if (K > 0) {
{
tools::segmented_sieve sieve(N - K + 1, N);
for (ll i = N - K + 1; i <= N; ++i) {
for (const auto p : sieve.prime_factor_range(i)) {
++nCk[p];
}
}
}
{
tools::linear_sieve<ll> sieve(K);
for (ll i = 1; i <= K; ++i) {
for (const auto p : sieve.prime_factor_range(i)) {
--nCk[p];
}
}
}
}
mint answer(1);
for (const auto& [p, q] : nCk) {
answer *= mint(q + 1);
}
return answer;
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
assert_that(solve(260522LL, 0) == mint::raw(1));
assert_that(solve(250877914575LL, 0) == mint::raw(1));
assert_that(solve(436426LL, 450) == mint::raw(702197356));
assert_that(solve(917861648772LL, 118991) == mint::raw(815979133));
assert_that(solve(933447LL, 818) == mint::raw(722540106));
assert_that(solve(426262703497LL, 509745) == mint::raw(561446205));
assert_that(solve(407775LL, 228) == mint::raw(678364367));
assert_that(solve(828731963982LL, 391307) == mint::raw(692228966));
assert_that(solve(968417LL, 880) == mint::raw(960576648));
assert_that(solve(258982631932LL, 309269) == mint::raw(985409932));
assert_that(solve(999966000289LL, 999983) == mint::raw(141645597));
assert_that(solve(4922986896LL, 70164) == mint::raw(104415157));
assert_that(solve(722500LL, 850) == mint::raw(914586245));
assert_that(solve(731189169216LL, 855096) == mint::raw(623303382));
assert_that(solve(286225LL, 535) == mint::raw(931530455));
assert_that(solve(329211LL, 134927) == mint::raw(800661327));
assert_that(solve(296303238506LL, 552101) == mint::raw(698851498));
assert_that(solve(686568LL, 338756) == mint::raw(287185310));
assert_that(solve(16125660016LL, 861628) == mint::raw(183596625));
assert_that(solve(296263LL, 130165) == mint::raw(959904952));
assert_that(solve(951492601449LL, 992483) == mint::raw(455362283));
assert_that(solve(890310LL, 403135) == mint::raw(756935960));
assert_that(solve(481782177068LL, 898261) == mint::raw(98360632));
assert_that(solve(8580LL, 7465) == mint::raw(435659331));
assert_that(solve(449218LL, 372632) == mint::raw(236553770));
assert_that(solve(594328LL, 392059) == mint::raw(175736881));
assert_that(solve(829355LL, 758690) == mint::raw(559233694));
assert_that(solve(323798LL, 323798) == mint::raw(1));
assert_that(solve(231618LL, 231618) == mint::raw(1));
assert_that(solve(1000000000000LL, 0) == mint::raw(1));
assert_that(solve(999999999995LL, 999991) == mint::raw(181590252));
assert_that(solve(999999999996LL, 420202) == mint::raw(289049345));
assert_that(solve(999999999994LL, 1) == mint::raw(8));
assert_that(solve(999999999992LL, 999998) == mint::raw(290102227));
assert_that(solve(999999999999LL, 328262) == mint::raw(577126736));
assert_that(solve(1LL, 0) == mint::raw(1));
assert_that(solve(1LL, 1) == mint::raw(1));
assert_that(solve(5LL, 2) == mint::raw(4));
assert_that(solve(103LL, 3) == mint::raw(8));
assert_that(solve(1000000000000LL, 1000000) == mint::raw(110520107));
return 0;
}
#line 1 "tests/segmented_sieve/prime_factor_range.test.cpp"
// competitive-verifier: STANDALONE
// Source: https://atcoder.jp/contests/abc227/tasks/abc227_g
#include <iostream>
#line 1 "lib/ac-library/atcoder/modint.hpp"
#include <cassert>
#include <numeric>
#include <type_traits>
#ifdef _MSC_VER
#include <intrin.h>
#endif
#line 1 "lib/ac-library/atcoder/internal_math.hpp"
#include <utility>
#ifdef _MSC_VER
#include <intrin.h>
#endif
namespace atcoder {
namespace internal {
// @param m `1 <= m`
// @return x mod m
constexpr long long safe_mod(long long x, long long m) {
x %= m;
if (x < 0) x += m;
return x;
}
// Fast modular multiplication by barrett reduction
// Reference: https://en.wikipedia.org/wiki/Barrett_reduction
// NOTE: reconsider after Ice Lake
struct barrett {
unsigned int _m;
unsigned long long im;
// @param m `1 <= m`
explicit barrett(unsigned int m) : _m(m), im((unsigned long long)(-1) / m + 1) {}
// @return m
unsigned int umod() const { return _m; }
// @param a `0 <= a < m`
// @param b `0 <= b < m`
// @return `a * b % m`
unsigned int mul(unsigned int a, unsigned int b) const {
// [1] m = 1
// a = b = im = 0, so okay
// [2] m >= 2
// im = ceil(2^64 / m)
// -> im * m = 2^64 + r (0 <= r < m)
// let z = a*b = c*m + d (0 <= c, d < m)
// a*b * im = (c*m + d) * im = c*(im*m) + d*im = c*2^64 + c*r + d*im
// c*r + d*im < m * m + m * im < m * m + 2^64 + m <= 2^64 + m * (m + 1) < 2^64 * 2
// ((ab * im) >> 64) == c or c + 1
unsigned long long z = a;
z *= b;
#ifdef _MSC_VER
unsigned long long x;
_umul128(z, im, &x);
#else
unsigned long long x =
(unsigned long long)(((unsigned __int128)(z)*im) >> 64);
#endif
unsigned long long y = x * _m;
return (unsigned int)(z - y + (z < y ? _m : 0));
}
};
// @param n `0 <= n`
// @param m `1 <= m`
// @return `(x ** n) % m`
constexpr long long pow_mod_constexpr(long long x, long long n, int m) {
if (m == 1) return 0;
unsigned int _m = (unsigned int)(m);
unsigned long long r = 1;
unsigned long long y = safe_mod(x, m);
while (n) {
if (n & 1) r = (r * y) % _m;
y = (y * y) % _m;
n >>= 1;
}
return r;
}
// Reference:
// M. Forisek and J. Jancina,
// Fast Primality Testing for Integers That Fit into a Machine Word
// @param n `0 <= n`
constexpr bool is_prime_constexpr(int n) {
if (n <= 1) return false;
if (n == 2 || n == 7 || n == 61) return true;
if (n % 2 == 0) return false;
long long d = n - 1;
while (d % 2 == 0) d /= 2;
constexpr long long bases[3] = {2, 7, 61};
for (long long a : bases) {
long long t = d;
long long y = pow_mod_constexpr(a, t, n);
while (t != n - 1 && y != 1 && y != n - 1) {
y = y * y % n;
t <<= 1;
}
if (y != n - 1 && t % 2 == 0) {
return false;
}
}
return true;
}
template <int n> constexpr bool is_prime = is_prime_constexpr(n);
// @param b `1 <= b`
// @return pair(g, x) s.t. g = gcd(a, b), xa = g (mod b), 0 <= x < b/g
constexpr std::pair<long long, long long> inv_gcd(long long a, long long b) {
a = safe_mod(a, b);
if (a == 0) return {b, 0};
// Contracts:
// [1] s - m0 * a = 0 (mod b)
// [2] t - m1 * a = 0 (mod b)
// [3] s * |m1| + t * |m0| <= b
long long s = b, t = a;
long long m0 = 0, m1 = 1;
while (t) {
long long u = s / t;
s -= t * u;
m0 -= m1 * u; // |m1 * u| <= |m1| * s <= b
// [3]:
// (s - t * u) * |m1| + t * |m0 - m1 * u|
// <= s * |m1| - t * u * |m1| + t * (|m0| + |m1| * u)
// = s * |m1| + t * |m0| <= b
auto tmp = s;
s = t;
t = tmp;
tmp = m0;
m0 = m1;
m1 = tmp;
}
// by [3]: |m0| <= b/g
// by g != b: |m0| < b/g
if (m0 < 0) m0 += b / s;
return {s, m0};
}
// Compile time primitive root
// @param m must be prime
// @return primitive root (and minimum in now)
constexpr int primitive_root_constexpr(int m) {
if (m == 2) return 1;
if (m == 167772161) return 3;
if (m == 469762049) return 3;
if (m == 754974721) return 11;
if (m == 998244353) return 3;
int divs[20] = {};
divs[0] = 2;
int cnt = 1;
int x = (m - 1) / 2;
while (x % 2 == 0) x /= 2;
for (int i = 3; (long long)(i)*i <= x; i += 2) {
if (x % i == 0) {
divs[cnt++] = i;
while (x % i == 0) {
x /= i;
}
}
}
if (x > 1) {
divs[cnt++] = x;
}
for (int g = 2;; g++) {
bool ok = true;
for (int i = 0; i < cnt; i++) {
if (pow_mod_constexpr(g, (m - 1) / divs[i], m) == 1) {
ok = false;
break;
}
}
if (ok) return g;
}
}
template <int m> constexpr int primitive_root = primitive_root_constexpr(m);
// @param n `n < 2^32`
// @param m `1 <= m < 2^32`
// @return sum_{i=0}^{n-1} floor((ai + b) / m) (mod 2^64)
unsigned long long floor_sum_unsigned(unsigned long long n,
unsigned long long m,
unsigned long long a,
unsigned long long b) {
unsigned long long ans = 0;
while (true) {
if (a >= m) {
ans += n * (n - 1) / 2 * (a / m);
a %= m;
}
if (b >= m) {
ans += n * (b / m);
b %= m;
}
unsigned long long y_max = a * n + b;
if (y_max < m) break;
// y_max < m * (n + 1)
// floor(y_max / m) <= n
n = (unsigned long long)(y_max / m);
b = (unsigned long long)(y_max % m);
std::swap(m, a);
}
return ans;
}
} // namespace internal
} // namespace atcoder
#line 1 "lib/ac-library/atcoder/internal_type_traits.hpp"
#line 7 "lib/ac-library/atcoder/internal_type_traits.hpp"
namespace atcoder {
namespace internal {
#ifndef _MSC_VER
template <class T>
using is_signed_int128 =
typename std::conditional<std::is_same<T, __int128_t>::value ||
std::is_same<T, __int128>::value,
std::true_type,
std::false_type>::type;
template <class T>
using is_unsigned_int128 =
typename std::conditional<std::is_same<T, __uint128_t>::value ||
std::is_same<T, unsigned __int128>::value,
std::true_type,
std::false_type>::type;
template <class T>
using make_unsigned_int128 =
typename std::conditional<std::is_same<T, __int128_t>::value,
__uint128_t,
unsigned __int128>;
template <class T>
using is_integral = typename std::conditional<std::is_integral<T>::value ||
is_signed_int128<T>::value ||
is_unsigned_int128<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using is_signed_int = typename std::conditional<(is_integral<T>::value &&
std::is_signed<T>::value) ||
is_signed_int128<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using is_unsigned_int =
typename std::conditional<(is_integral<T>::value &&
std::is_unsigned<T>::value) ||
is_unsigned_int128<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using to_unsigned = typename std::conditional<
is_signed_int128<T>::value,
make_unsigned_int128<T>,
typename std::conditional<std::is_signed<T>::value,
std::make_unsigned<T>,
std::common_type<T>>::type>::type;
#else
template <class T> using is_integral = typename std::is_integral<T>;
template <class T>
using is_signed_int =
typename std::conditional<is_integral<T>::value && std::is_signed<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using is_unsigned_int =
typename std::conditional<is_integral<T>::value &&
std::is_unsigned<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using to_unsigned = typename std::conditional<is_signed_int<T>::value,
std::make_unsigned<T>,
std::common_type<T>>::type;
#endif
template <class T>
using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>;
template <class T>
using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>;
template <class T> using to_unsigned_t = typename to_unsigned<T>::type;
} // namespace internal
} // namespace atcoder
#line 14 "lib/ac-library/atcoder/modint.hpp"
namespace atcoder {
namespace internal {
struct modint_base {};
struct static_modint_base : modint_base {};
template <class T> using is_modint = std::is_base_of<modint_base, T>;
template <class T> using is_modint_t = std::enable_if_t<is_modint<T>::value>;
} // namespace internal
template <int m, std::enable_if_t<(1 <= m)>* = nullptr>
struct static_modint : internal::static_modint_base {
using mint = static_modint;
public:
static constexpr int mod() { return m; }
static mint raw(int v) {
mint x;
x._v = v;
return x;
}
static_modint() : _v(0) {}
template <class T, internal::is_signed_int_t<T>* = nullptr>
static_modint(T v) {
long long x = (long long)(v % (long long)(umod()));
if (x < 0) x += umod();
_v = (unsigned int)(x);
}
template <class T, internal::is_unsigned_int_t<T>* = nullptr>
static_modint(T v) {
_v = (unsigned int)(v % umod());
}
int val() const { return _v; }
mint& operator++() {
_v++;
if (_v == umod()) _v = 0;
return *this;
}
mint& operator--() {
if (_v == 0) _v = umod();
_v--;
return *this;
}
mint operator++(int) {
mint result = *this;
++*this;
return result;
}
mint operator--(int) {
mint result = *this;
--*this;
return result;
}
mint& operator+=(const mint& rhs) {
_v += rhs._v;
if (_v >= umod()) _v -= umod();
return *this;
}
mint& operator-=(const mint& rhs) {
_v -= rhs._v;
if (_v >= umod()) _v += umod();
return *this;
}
mint& operator*=(const mint& rhs) {
unsigned long long z = _v;
z *= rhs._v;
_v = (unsigned int)(z % umod());
return *this;
}
mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }
mint operator+() const { return *this; }
mint operator-() const { return mint() - *this; }
mint pow(long long n) const {
assert(0 <= n);
mint x = *this, r = 1;
while (n) {
if (n & 1) r *= x;
x *= x;
n >>= 1;
}
return r;
}
mint inv() const {
if (prime) {
assert(_v);
return pow(umod() - 2);
} else {
auto eg = internal::inv_gcd(_v, m);
assert(eg.first == 1);
return eg.second;
}
}
friend mint operator+(const mint& lhs, const mint& rhs) {
return mint(lhs) += rhs;
}
friend mint operator-(const mint& lhs, const mint& rhs) {
return mint(lhs) -= rhs;
}
friend mint operator*(const mint& lhs, const mint& rhs) {
return mint(lhs) *= rhs;
}
friend mint operator/(const mint& lhs, const mint& rhs) {
return mint(lhs) /= rhs;
}
friend bool operator==(const mint& lhs, const mint& rhs) {
return lhs._v == rhs._v;
}
friend bool operator!=(const mint& lhs, const mint& rhs) {
return lhs._v != rhs._v;
}
private:
unsigned int _v;
static constexpr unsigned int umod() { return m; }
static constexpr bool prime = internal::is_prime<m>;
};
template <int id> struct dynamic_modint : internal::modint_base {
using mint = dynamic_modint;
public:
static int mod() { return (int)(bt.umod()); }
static void set_mod(int m) {
assert(1 <= m);
bt = internal::barrett(m);
}
static mint raw(int v) {
mint x;
x._v = v;
return x;
}
dynamic_modint() : _v(0) {}
template <class T, internal::is_signed_int_t<T>* = nullptr>
dynamic_modint(T v) {
long long x = (long long)(v % (long long)(mod()));
if (x < 0) x += mod();
_v = (unsigned int)(x);
}
template <class T, internal::is_unsigned_int_t<T>* = nullptr>
dynamic_modint(T v) {
_v = (unsigned int)(v % mod());
}
int val() const { return _v; }
mint& operator++() {
_v++;
if (_v == umod()) _v = 0;
return *this;
}
mint& operator--() {
if (_v == 0) _v = umod();
_v--;
return *this;
}
mint operator++(int) {
mint result = *this;
++*this;
return result;
}
mint operator--(int) {
mint result = *this;
--*this;
return result;
}
mint& operator+=(const mint& rhs) {
_v += rhs._v;
if (_v >= umod()) _v -= umod();
return *this;
}
mint& operator-=(const mint& rhs) {
_v += mod() - rhs._v;
if (_v >= umod()) _v -= umod();
return *this;
}
mint& operator*=(const mint& rhs) {
_v = bt.mul(_v, rhs._v);
return *this;
}
mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }
mint operator+() const { return *this; }
mint operator-() const { return mint() - *this; }
mint pow(long long n) const {
assert(0 <= n);
mint x = *this, r = 1;
while (n) {
if (n & 1) r *= x;
x *= x;
n >>= 1;
}
return r;
}
mint inv() const {
auto eg = internal::inv_gcd(_v, mod());
assert(eg.first == 1);
return eg.second;
}
friend mint operator+(const mint& lhs, const mint& rhs) {
return mint(lhs) += rhs;
}
friend mint operator-(const mint& lhs, const mint& rhs) {
return mint(lhs) -= rhs;
}
friend mint operator*(const mint& lhs, const mint& rhs) {
return mint(lhs) *= rhs;
}
friend mint operator/(const mint& lhs, const mint& rhs) {
return mint(lhs) /= rhs;
}
friend bool operator==(const mint& lhs, const mint& rhs) {
return lhs._v == rhs._v;
}
friend bool operator!=(const mint& lhs, const mint& rhs) {
return lhs._v != rhs._v;
}
private:
unsigned int _v;
static internal::barrett bt;
static unsigned int umod() { return bt.umod(); }
};
template <int id> internal::barrett dynamic_modint<id>::bt(998244353);
using modint998244353 = static_modint<998244353>;
using modint1000000007 = static_modint<1000000007>;
using modint = dynamic_modint<-1>;
namespace internal {
template <class T>
using is_static_modint = std::is_base_of<internal::static_modint_base, T>;
template <class T>
using is_static_modint_t = std::enable_if_t<is_static_modint<T>::value>;
template <class> struct is_dynamic_modint : public std::false_type {};
template <int id>
struct is_dynamic_modint<dynamic_modint<id>> : public std::true_type {};
template <class T>
using is_dynamic_modint_t = std::enable_if_t<is_dynamic_modint<T>::value>;
} // namespace internal
} // namespace atcoder
#line 1 "tools/assert_that.hpp"
#line 5 "tools/assert_that.hpp"
#include <cstdlib>
#define assert_that_impl(cond, file, line, func) do {\
if (!cond) {\
std::cerr << file << ':' << line << ": " << func << ": Assertion `" << #cond << "' failed." << '\n';\
std::exit(EXIT_FAILURE);\
}\
} while (false)
#define assert_that(...) assert_that_impl((__VA_ARGS__), __FILE__, __LINE__, __func__)
#line 1 "tools/linear_sieve.hpp"
#include <algorithm>
#line 6 "tools/linear_sieve.hpp"
#include <cstddef>
#include <iterator>
#include <ranges>
#include <tuple>
#line 11 "tools/linear_sieve.hpp"
#include <vector>
namespace tools {
template <typename T>
class linear_sieve {
std::vector<int> m_primes;
std::vector<int> m_lpf;
std::vector<int> m_ord;
std::vector<int> m_pow;
int N() const {
return this->m_lpf.size() - 1;
}
public:
class prime_factor_view : public std::ranges::view_interface<prime_factor_view> {
tools::linear_sieve<T> const *m_parent;
int m_n;
public:
class iterator {
tools::linear_sieve<T> const *m_parent;
int m_n;
public:
using difference_type = std::ptrdiff_t;
using value_type = T;
using reference = T;
using pointer = const T*;
using iterator_category = std::input_iterator_tag;
iterator() = default;
iterator(tools::linear_sieve<T> const * const parent, const int n) : m_parent(parent), m_n(n) {
}
reference operator*() const {
return this->m_parent->m_lpf[this->m_n];
}
iterator& operator++() {
this->m_n /= **this;
return *this;
}
iterator operator++(int) {
const auto self = *this;
++*this;
return self;
}
friend bool operator==(const iterator lhs, const iterator rhs) {
assert(lhs.m_parent == rhs.m_parent);
return lhs.m_n == rhs.m_n;
}
friend bool operator!=(const iterator lhs, const iterator rhs) {
return !(lhs == rhs);
}
};
prime_factor_view() = default;
prime_factor_view(tools::linear_sieve<T> const * const parent, const int n) : m_parent(parent), m_n(n) {
}
iterator begin() const {
return iterator(this->m_parent, this->m_n);
};
iterator end() const {
return iterator(this->m_parent, 1);
}
};
class distinct_prime_factor_view : public std::ranges::view_interface<distinct_prime_factor_view> {
tools::linear_sieve<T> const *m_parent;
int m_n;
public:
class iterator {
tools::linear_sieve<T> const *m_parent;
int m_n;
public:
using difference_type = std::ptrdiff_t;
using value_type = std::tuple<T, T, T>;
using reference = std::tuple<T, T, T>;
using pointer = const std::tuple<T, T, T>*;
using iterator_category = std::input_iterator_tag;
iterator() = default;
iterator(tools::linear_sieve<T> const * const parent, const int n) : m_parent(parent), m_n(n) {
}
reference operator*() const {
return value_type(this->m_parent->m_lpf[this->m_n], this->m_parent->m_ord[this->m_n], this->m_parent->m_pow[this->m_n]);
}
iterator& operator++() {
this->m_n /= this->m_parent->m_pow[this->m_n];
return *this;
}
iterator operator++(int) {
const auto self = *this;
++*this;
return self;
}
friend bool operator==(const iterator lhs, const iterator rhs) {
assert(lhs.m_parent == rhs.m_parent);
return lhs.m_n == rhs.m_n;
}
friend bool operator!=(const iterator lhs, const iterator rhs) {
return !(lhs == rhs);
}
};
distinct_prime_factor_view() = default;
distinct_prime_factor_view(tools::linear_sieve<T> const * const parent, const int n) : m_parent(parent), m_n(n) {
}
iterator begin() const {
return iterator(this->m_parent, this->m_n);
};
iterator end() const {
return iterator(this->m_parent, 1);
}
};
class prime_view : public std::ranges::view_interface<prime_view> {
tools::linear_sieve<T> const *m_parent;
int m_begin;
int m_end;
public:
class iterator {
tools::linear_sieve<T> const *m_parent;
int m_i;
public:
using difference_type = std::ptrdiff_t;
using value_type = T;
using reference = T;
using pointer = const T*;
using iterator_category = std::input_iterator_tag;
iterator() = default;
iterator(tools::linear_sieve<T> const * const parent, const int i) : m_parent(parent), m_i(i) {
}
reference operator*() const {
return this->m_parent->m_primes[this->m_i];
}
iterator& operator++() {
++this->m_i;
return *this;
}
iterator operator++(int) {
const auto self = *this;
++*this;
return self;
}
friend bool operator==(const iterator lhs, const iterator rhs) {
assert(lhs.m_parent == rhs.m_parent);
return lhs.m_i == rhs.m_i;
}
friend bool operator!=(const iterator lhs, const iterator rhs) {
return !(lhs == rhs);
}
};
prime_view() = default;
prime_view(tools::linear_sieve<T> const * const parent, const int l, const int r) :
m_parent(parent),
m_begin(std::distance(parent->m_primes.begin(), std::ranges::lower_bound(parent->m_primes, l))),
m_end(std::distance(parent->m_primes.begin(), std::ranges::upper_bound(parent->m_primes, r))) {
}
iterator begin() const {
return iterator(this->m_parent, this->m_begin);
};
iterator end() const {
return iterator(this->m_parent, this->m_end);
}
};
linear_sieve() = default;
explicit linear_sieve(const int N) : m_lpf(N + 1), m_ord(N + 1), m_pow(N + 1) {
assert(N >= 1);
for (int n = 2; n <= N; ++n) {
if (!this->m_lpf[n]) {
this->m_primes.push_back(n);
this->m_lpf[n] = n;
this->m_ord[n] = 1;
this->m_pow[n] = n;
}
for (auto it = this->m_primes.begin(); it != this->m_primes.end() && *it <= this->m_lpf[n] && n * *it <= N; ++it) {
this->m_lpf[n * *it] = *it;
if (*it < this->m_lpf[n]) {
this->m_ord[n * *it] = 1;
this->m_pow[n * *it] = *it;
} else {
this->m_ord[n * *it] = this->m_ord[n] + 1;
this->m_pow[n * *it] = this->m_pow[n] * *it;
}
}
}
}
bool is_prime(const int n) const {
assert(1 <= n && n <= this->N());
return n >= 2 && this->m_lpf[n] == n;
}
prime_factor_view prime_factor_range(const int n) const {
assert(1 <= n && n <= this->N());
return prime_factor_view(this, n);
}
distinct_prime_factor_view distinct_prime_factor_range(const int n) const {
assert(1 <= n && n <= this->N());
return distinct_prime_factor_view(this, n);
}
prime_view prime_range(const int l, const int r) const {
assert(1 <= l && l <= r && r <= this->N());
return prime_view(this, l, r);
}
std::vector<T> divisors(const int n) const {
assert(1 <= n && n <= this->N());
std::vector<T> D{1};
for ([[maybe_unused]] const auto& [p, q, pq] : this->distinct_prime_factor_range(n)) {
const int end = D.size();
for (int e = 1, pe = 1; e <= q; ++e) {
pe *= p;
for (int i = 0; i < end; ++i) {
D.push_back(D[i] * pe);
}
}
}
return D;
}
std::vector<T> sorted_divisors(const int n) const {
auto D = this->divisors(n);
std::ranges::sort(D);
return D;
}
std::vector<T> divisor_counts() const {
std::vector<std::pair<int, int>> dp(this->N() + 1);
dp[0] = std::make_pair(0, 0);
dp[1] = std::make_pair(1, 1);
for (int i = 2; i <= this->N(); ++i) {
const auto& prev = dp[i / this->m_lpf[i]];
if (this->m_lpf[i / this->m_lpf[i]] == this->m_lpf[i]) {
dp[i] = std::make_pair(prev.first + 1, prev.second);
} else {
dp[i] = std::make_pair(2, prev.first * prev.second);
}
}
std::vector<T> divisor_counts(this->N() + 1);
for (int i = 0; i <= this->N(); ++i) {
divisor_counts[i] = dp[i].first * dp[i].second;
}
return divisor_counts;
}
};
}
#line 1 "tools/segmented_sieve.hpp"
#line 1 "tools/block_ceil.hpp"
#line 1 "tools/ceil.hpp"
#line 1 "tools/non_bool_integral.hpp"
#include <concepts>
#line 1 "tools/integral.hpp"
#line 1 "tools/is_integral.hpp"
#line 5 "tools/is_integral.hpp"
namespace tools {
template <typename T>
struct is_integral : std::is_integral<T> {};
template <typename T>
inline constexpr bool is_integral_v = tools::is_integral<T>::value;
}
#line 5 "tools/integral.hpp"
namespace tools {
template <typename T>
concept integral = tools::is_integral_v<T>;
}
#line 7 "tools/non_bool_integral.hpp"
namespace tools {
template <typename T>
concept non_bool_integral = tools::integral<T> && !std::same_as<std::remove_cv_t<T>, bool>;
}
#line 1 "tools/is_unsigned.hpp"
#line 5 "tools/is_unsigned.hpp"
namespace tools {
template <typename T>
struct is_unsigned : std::is_unsigned<T> {};
template <typename T>
inline constexpr bool is_unsigned_v = tools::is_unsigned<T>::value;
}
#line 8 "tools/ceil.hpp"
namespace tools {
template <tools::non_bool_integral M, tools::non_bool_integral N>
constexpr std::common_type_t<M, N> ceil(const M x, const N y) noexcept {
assert(y != 0);
if (y >= 0) {
if (x > 0) {
return (x - 1) / y + 1;
} else {
if constexpr (tools::is_unsigned_v<std::common_type_t<M, N>>) {
return 0;
} else {
return x / y;
}
}
} else {
if (x >= 0) {
if constexpr (tools::is_unsigned_v<std::common_type_t<M, N>>) {
return 0;
} else {
return x / y;
}
} else {
return (x + 1) / y + 1;
}
}
}
}
#line 7 "tools/block_ceil.hpp"
namespace tools {
template <typename M, typename N>
constexpr std::common_type_t<M, N> block_ceil(const M x, const N y) noexcept {
assert(y > 0);
return tools::ceil(x, y) * y;
}
}
#line 1 "tools/floor_sqrt.hpp"
#line 5 "tools/floor_sqrt.hpp"
namespace tools {
template <typename T>
T floor_sqrt(const T n) {
assert(n >= 0);
T ok = 0;
T ng;
for (ng = 1; ng <= n / ng; ng *= 2);
while (ng - ok > 1) {
const T mid = ok + (ng - ok) / 2;
if (mid <= n / mid) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
}
#line 14 "tools/segmented_sieve.hpp"
namespace tools {
class segmented_sieve {
std::vector<int> m_small_primes;
std::vector<std::tuple<int, int, int>> m_small_factors;
std::vector<long long> m_large_primes;
std::vector<std::tuple<long long, int, long long, int>> m_large_factors;
long long m_l;
long long m_r;
public:
class prime_factor_view : public std::ranges::view_interface<prime_factor_view> {
tools::segmented_sieve const *m_parent;
long long m_n;
public:
class iterator {
tools::segmented_sieve const *m_parent;
int m_i;
int m_j;
public:
using difference_type = std::ptrdiff_t;
using value_type = long long;
using reference = long long;
using pointer = const long long*;
using iterator_category = std::input_iterator_tag;
iterator() = default;
iterator(tools::segmented_sieve const * const parent, const int i, const int j) : m_parent(parent), m_i(i), m_j(j) {
}
reference operator*() const {
if (this->m_i >= 0) {
return std::get<0>(this->m_parent->m_small_factors[this->m_i]);
} else {
return std::get<0>(this->m_parent->m_large_factors[~this->m_i]);
}
}
iterator& operator++() {
if (this->m_i >= 0) {
++this->m_j;
if (this->m_j >= std::get<1>(this->m_parent->m_small_factors[this->m_i])) {
this->m_i /= std::get<2>(this->m_parent->m_small_factors[this->m_i]);
this->m_j = 0;
}
} else {
++this->m_j;
if (this->m_j >= std::get<1>(this->m_parent->m_large_factors[~this->m_i])) {
this->m_i = ~std::get<3>(this->m_parent->m_large_factors[~this->m_i]);
this->m_j = 0;
}
}
return *this;
}
iterator operator++(int) {
const auto self = *this;
++*this;
return self;
}
friend bool operator==(const iterator lhs, const iterator rhs) {
assert(lhs.m_parent == rhs.m_parent);
return lhs.m_i == rhs.m_i && lhs.m_j == rhs.m_j;
}
friend bool operator!=(const iterator lhs, const iterator rhs) {
return !(lhs == rhs);
}
};
prime_factor_view() = default;
prime_factor_view(tools::segmented_sieve const * const parent, const long long n) : m_parent(parent), m_n(n) {
}
iterator begin() const {
return iterator(this->m_parent, this->m_n <= this->m_parent->sqrt_r() ? this->m_n : ~(this->m_n - this->m_parent->m_l), 0);
};
iterator end() const {
return iterator(this->m_parent, 1, 0);
}
};
class distinct_prime_factor_view : public std::ranges::view_interface<distinct_prime_factor_view> {
tools::segmented_sieve const *m_parent;
long long m_n;
public:
class iterator {
tools::segmented_sieve const *m_parent;
int m_i;
public:
using difference_type = std::ptrdiff_t;
using value_type = std::tuple<long long, long long, long long>;
using reference = std::tuple<long long, long long, long long>;
using pointer = const std::tuple<long long, long long, long long>*;
using iterator_category = std::input_iterator_tag;
iterator() = default;
iterator(tools::segmented_sieve const * const parent, const int i) : m_parent(parent), m_i(i) {
}
reference operator*() const {
if (this->m_i >= 0) {
return this->m_parent->m_small_factors[this->m_i];
} else {
[[maybe_unused]] const auto& [p, q, pq, next_i] = this->m_parent->m_large_factors[~this->m_i];
return value_type(p, q, pq);
}
}
iterator& operator++() {
if (this->m_i >= 0) {
this->m_i /= std::get<2>(this->m_parent->m_small_factors[this->m_i]);
} else {
this->m_i = ~std::get<3>(this->m_parent->m_large_factors[~this->m_i]);
}
return *this;
}
iterator operator++(int) {
const auto self = *this;
++*this;
return self;
}
friend bool operator==(const iterator lhs, const iterator rhs) {
assert(lhs.m_parent == rhs.m_parent);
return lhs.m_i == rhs.m_i;
}
friend bool operator!=(const iterator lhs, const iterator rhs) {
return !(lhs == rhs);
}
};
distinct_prime_factor_view() = default;
distinct_prime_factor_view(tools::segmented_sieve const * const parent, const long long n) : m_parent(parent), m_n(n) {
}
iterator begin() const {
return iterator(this->m_parent, this->m_n <= this->m_parent->sqrt_r() ? this->m_n : ~(this->m_n - this->m_parent->m_l));
};
iterator end() const {
return iterator(this->m_parent, 1);
}
};
class prime_view : public std::ranges::view_interface<prime_view> {
tools::segmented_sieve const *m_parent;
int m_begin;
int m_end;
public:
class iterator {
tools::segmented_sieve const *m_parent;
int m_i;
public:
using difference_type = std::ptrdiff_t;
using value_type = long long;
using reference = long long;
using pointer = const long long*;
using iterator_category = std::input_iterator_tag;
iterator() = default;
iterator(tools::segmented_sieve const * const parent, const int i) : m_parent(parent), m_i(i) {
}
reference operator*() const {
if (this->m_i >= 0) {
return this->m_parent->m_small_primes[this->m_i];
} else {
return this->m_parent->m_large_primes[~this->m_i];
}
}
iterator& operator++() {
if (this->m_i >= 0) {
++this->m_i;
if (this->m_i >= std::ssize(this->m_parent->m_small_primes)) {
this->m_i = ~std::distance(this->m_parent->m_large_primes.begin(), std::ranges::upper_bound(this->m_parent->m_large_primes, this->m_parent->sqrt_r()));
}
} else {
--this->m_i;
}
return *this;
}
iterator operator++(int) {
const auto self = *this;
++*this;
return self;
}
friend bool operator==(const iterator lhs, const iterator rhs) {
assert(lhs.m_parent == rhs.m_parent);
return lhs.m_i == rhs.m_i;
}
friend bool operator!=(const iterator lhs, const iterator rhs) {
return !(lhs == rhs);
}
};
prime_view() = default;
prime_view(tools::segmented_sieve const * const parent, const long long l, const long long r) :
m_parent(parent),
m_begin(
!parent->m_small_primes.empty() && l <= parent->m_small_primes.back()
? std::distance(parent->m_small_primes.begin(), std::ranges::lower_bound(parent->m_small_primes, l))
: ~std::distance(parent->m_large_primes.begin(), std::ranges::lower_bound(parent->m_large_primes, l))
),
m_end(
!parent->m_small_primes.empty() && r < parent->m_small_primes.back()
? std::distance(parent->m_small_primes.begin(), std::ranges::upper_bound(parent->m_small_primes, r))
: ~std::distance(parent->m_large_primes.begin(), std::ranges::upper_bound(parent->m_large_primes, r))
) {
}
iterator begin() const {
return iterator(this->m_parent, this->m_begin);
};
iterator end() const {
return iterator(this->m_parent, this->m_end);
}
};
segmented_sieve() = default;
segmented_sieve(const long long l, const long long r) : m_small_factors(tools::floor_sqrt(r) + 1), m_large_factors(r - l + 1), m_l(l), m_r(r) {
assert(1 <= l && l <= r);
for (int n = 2; n <= this->sqrt_r(); ++n) {
if (!std::get<0>(this->m_small_factors[n])) {
this->m_small_primes.push_back(n);
this->m_small_factors[n] = {n, 1, n};
}
for (auto it = this->m_small_primes.begin(); it != this->m_small_primes.end() && *it <= std::get<0>(this->m_small_factors[n]) && n * *it <= this->sqrt_r(); ++it) {
std::get<0>(this->m_small_factors[n * *it]) = *it;
if (*it < std::get<0>(this->m_small_factors[n])) {
std::get<1>(this->m_small_factors[n * *it]) = 1;
std::get<2>(this->m_small_factors[n * *it]) = *it;
} else {
std::get<1>(this->m_small_factors[n * *it]) = std::get<1>(this->m_small_factors[n]) + 1;
std::get<2>(this->m_small_factors[n * *it]) = std::get<2>(this->m_small_factors[n]) * *it;
}
}
}
std::vector<long long> rem(r - l + 1);
for (long long n = l; n <= r; ++n) {
rem[n - l] = n;
}
std::vector<int> last(r - l + 1, -1);
for (const auto p : this->m_small_primes) {
for (long long n = tools::block_ceil(l, p); n <= r; n += p) {
int curr;
if (last[n - l] >= 0) {
curr = this->m_large_factors.size();
this->m_large_factors.emplace_back(p, 0, 1, ~1);
std::get<3>(this->m_large_factors[last[n - l]]) = curr;
} else {
curr = n - l;
this->m_large_factors[curr] = {p, 0, 1, ~1};
}
do {
rem[n - l] /= p;
++std::get<1>(this->m_large_factors[curr]);
std::get<2>(this->m_large_factors[curr]) *= p;
} while (rem[n - l] % p == 0);
last[n - l] = curr;
}
}
for (long long n = l; n <= r; ++n) {
if (last[n - l] >= 0) {
if (rem[n - l] > 1) {
std::get<3>(this->m_large_factors[last[n - l]]) = this->m_large_factors.size();
this->m_large_factors.emplace_back(rem[n - l], 1, rem[n - l], ~1);
}
} else {
if (n > 1) {
this->m_large_primes.push_back(n);
this->m_large_factors[n - l] = {n, 1, n, ~1};
}
}
}
}
long long sqrt_r() const {
return this->m_small_factors.size() - 1;
}
long long l() const {
return this->m_l;
}
long long r() const {
return this->m_r;
}
bool is_prime(const long long n) const {
assert((1 <= n && n <= this->sqrt_r()) || (this->m_l <= n && n <= this->m_r));
if (n <= this->sqrt_r()) {
return n >= 2 && std::get<0>(this->m_small_factors[n]) == n;
} else {
return std::get<0>(this->m_large_factors[n - this->m_l]) == n;
}
}
prime_factor_view prime_factor_range(const long long n) const {
assert((1 <= n && n <= this->sqrt_r()) || (this->m_l <= n && n <= this->m_r));
return prime_factor_view(this, n);
}
distinct_prime_factor_view distinct_prime_factor_range(const long long n) const {
assert((1 <= n && n <= this->sqrt_r()) || (this->m_l <= n && n <= this->m_r));
return distinct_prime_factor_view(this, n);
}
prime_view prime_range(const long long l, const long long r) const {
#ifndef NDEBUG
if (this->sqrt_r() + 1 < this->l()) {
assert((1 <= l && l <= r && r <= this->sqrt_r()) || (this->m_l <= l && l <= r && r <= this->m_r));
} else {
assert(1 <= l && l <= r && r <= this->m_r);
}
#endif
return prime_view(this, l, r);
}
std::vector<long long> divisors(const long long n) const {
assert((1 <= n && n <= this->sqrt_r()) || (this->m_l <= n && n <= this->m_r));
std::vector<long long> D{1};
for ([[maybe_unused]] const auto& [p, q, pq] : this->distinct_prime_factor_range(n)) {
const int end = D.size();
for (long long e = 1, pe = 1; e <= q; ++e) {
pe *= p;
for (int i = 0; i < end; ++i) {
D.push_back(D[i] * pe);
}
}
}
return D;
}
std::vector<long long> sorted_divisors(const long long n) const {
auto D = this->divisors(n);
std::ranges::sort(D);
return D;
}
std::pair<std::vector<long long>, std::vector<long long>> divisor_counts() const {
std::vector<std::pair<int, int>> dp(this->sqrt_r() + 1);
dp[0] = std::make_pair(0, 0);
dp[1] = std::make_pair(1, 1);
for (int i = 2; i <= this->sqrt_r(); ++i) {
const auto& prev = dp[i / std::get<0>(this->m_small_factors[i])];
if (std::get<0>(this->m_small_factors[i / std::get<0>(this->m_small_factors[i])]) == std::get<0>(this->m_small_factors[i])) {
dp[i] = std::make_pair(prev.first + 1, prev.second);
} else {
dp[i] = std::make_pair(2, prev.first * prev.second);
}
}
std::vector<long long> small(this->sqrt_r() + 1);
for (int i = 0; i <= this->sqrt_r(); ++i) {
small[i] = dp[i].first * dp[i].second;
}
std::vector<long long> large(this->m_r - this->m_l + 1);
for (long long n = this->m_l; n <= this->m_r; ++n) {
large[n - this->m_l] = 1;
for ([[maybe_unused]] const auto& [p, q, pq] : this->distinct_prime_factor_range(n)) {
large[n - this->m_l] *= q + 1;
}
}
return {small, large};
}
};
}
#line 1 "tools/unordered_map.hpp"
#include <functional>
#line 7 "tools/unordered_map.hpp"
#include <ext/pb_ds/assoc_container.hpp>
namespace tools {
template <typename Key, typename T, typename Hash = std::hash<Key>>
class unordered_map : public ::__gnu_pbds::gp_hash_table<Key, T, Hash> {
public:
using ::__gnu_pbds::gp_hash_table<Key, T, Hash>::gp_hash_table;
template <typename... Args>
auto emplace(Args&&... args) {
return this->insert(std::make_pair(std::forward<Args>(args)...));
}
template <typename M>
auto insert_or_assign(const Key& k, M&& obj) {
if (auto it = this->find(k); it != this->end()) {
it->second = obj;
return std::make_pair(it, false);
} else {
return this->emplace(k, obj);
}
}
};
}
#line 10 "tests/segmented_sieve/prime_factor_range.test.cpp"
using ll = long long;
using mint = atcoder::modint998244353;
mint solve(const ll N, const int K) {
tools::unordered_map<ll, ll> nCk;
if (K > 0) {
{
tools::segmented_sieve sieve(N - K + 1, N);
for (ll i = N - K + 1; i <= N; ++i) {
for (const auto p : sieve.prime_factor_range(i)) {
++nCk[p];
}
}
}
{
tools::linear_sieve<ll> sieve(K);
for (ll i = 1; i <= K; ++i) {
for (const auto p : sieve.prime_factor_range(i)) {
--nCk[p];
}
}
}
}
mint answer(1);
for (const auto& [p, q] : nCk) {
answer *= mint(q + 1);
}
return answer;
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
assert_that(solve(260522LL, 0) == mint::raw(1));
assert_that(solve(250877914575LL, 0) == mint::raw(1));
assert_that(solve(436426LL, 450) == mint::raw(702197356));
assert_that(solve(917861648772LL, 118991) == mint::raw(815979133));
assert_that(solve(933447LL, 818) == mint::raw(722540106));
assert_that(solve(426262703497LL, 509745) == mint::raw(561446205));
assert_that(solve(407775LL, 228) == mint::raw(678364367));
assert_that(solve(828731963982LL, 391307) == mint::raw(692228966));
assert_that(solve(968417LL, 880) == mint::raw(960576648));
assert_that(solve(258982631932LL, 309269) == mint::raw(985409932));
assert_that(solve(999966000289LL, 999983) == mint::raw(141645597));
assert_that(solve(4922986896LL, 70164) == mint::raw(104415157));
assert_that(solve(722500LL, 850) == mint::raw(914586245));
assert_that(solve(731189169216LL, 855096) == mint::raw(623303382));
assert_that(solve(286225LL, 535) == mint::raw(931530455));
assert_that(solve(329211LL, 134927) == mint::raw(800661327));
assert_that(solve(296303238506LL, 552101) == mint::raw(698851498));
assert_that(solve(686568LL, 338756) == mint::raw(287185310));
assert_that(solve(16125660016LL, 861628) == mint::raw(183596625));
assert_that(solve(296263LL, 130165) == mint::raw(959904952));
assert_that(solve(951492601449LL, 992483) == mint::raw(455362283));
assert_that(solve(890310LL, 403135) == mint::raw(756935960));
assert_that(solve(481782177068LL, 898261) == mint::raw(98360632));
assert_that(solve(8580LL, 7465) == mint::raw(435659331));
assert_that(solve(449218LL, 372632) == mint::raw(236553770));
assert_that(solve(594328LL, 392059) == mint::raw(175736881));
assert_that(solve(829355LL, 758690) == mint::raw(559233694));
assert_that(solve(323798LL, 323798) == mint::raw(1));
assert_that(solve(231618LL, 231618) == mint::raw(1));
assert_that(solve(1000000000000LL, 0) == mint::raw(1));
assert_that(solve(999999999995LL, 999991) == mint::raw(181590252));
assert_that(solve(999999999996LL, 420202) == mint::raw(289049345));
assert_that(solve(999999999994LL, 1) == mint::raw(8));
assert_that(solve(999999999992LL, 999998) == mint::raw(290102227));
assert_that(solve(999999999999LL, 328262) == mint::raw(577126736));
assert_that(solve(1LL, 0) == mint::raw(1));
assert_that(solve(1LL, 1) == mint::raw(1));
assert_that(solve(5LL, 2) == mint::raw(4));
assert_that(solve(103LL, 3) == mint::raw(8));
assert_that(solve(1000000000000LL, 1000000) == mint::raw(110520107));
return 0;
}