Tifa's CP Library

:heavy_check_mark: test/cpv/aizu-ntl/ntl_1_a.cpp

Depends on

Code

// competitive-verifier: PROBLEM https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/all/NTL_1_A
#include "../../../src/io/fastin/lib.hpp"
#include "../../../src/io/fastout/lib.hpp"
#include "../../../src/nt/pfactors/lib.hpp"

using namespace tifa_libs;
int main() {
  u64 n;
  fin_uint >> n;
  auto ans = pfactors<false>(n);
  fout << n << ":";
  for (auto k : ans) fout << ' ' << k;
  fout << '\n';
  return 0;
}
#line 1 "test/cpv/aizu-ntl/ntl_1_a.cpp"
// competitive-verifier: PROBLEM https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/all/NTL_1_A
#line 2 "src/io/fastin/lib.hpp"

#line 2 "src/util/alias/others/lib.hpp"

#line 2 "src/util/consts/lib.hpp"

#line 2 "src/util/alias/num/lib.hpp"

#line 2 "src/util/util/lib.hpp"
// https://github.com/Tiphereth-A/CP-lib
#include <bits/extc++.h>
// clang-format off
namespace tifa_libs {

#define CEXP constexpr
#define CEXPE constexpr explicit
#define CR const&
#define CP const*
#define PC *const
#define CPC const*const
#define TPN typename
#define NE noexcept
#define CNE const noexcept
#define ND [[nodiscard]]
#define cT_(...) std::conditional_t<sizeof(__VA_ARGS__) <= sizeof(size_t) * 2, __VA_ARGS__, __VA_ARGS__ CR>
// NOLINTNEXTLINE(misc-const-correctness)
#define flt_(T, i, l, r, ...) for (T i = (l), i##e = (r)__VA_OPT__(, ) __VA_ARGS__; i < i##e; ++i)
#define retif_(cond, if_true, ...) if cond return if_true __VA_OPT__(; else return __VA_ARGS__)
#ifdef ONLINE_JUDGE
#undef assert
#define assert(x) 42
#endif

using namespace std::ranges;
using namespace std::literals;

template <class T>
CEXP T abs(T x) NE { retif_((x < 0), -x, x); }

}  // namespace tifa_libs
// clang-format on
#line 4 "src/util/alias/num/lib.hpp"
// clang-format off
namespace tifa_libs {

#define mk0_(w, t) using w = t; using c##w = const t
#define mk_(w, t) mk0_(w, t); CEXP w operator""_##w(unsigned long long x) NE { return (w)x; }
mk_(i8, int8_t) mk_(u8, uint8_t) mk_(i16, int16_t) mk_(u16, uint16_t) mk_(i32, int32_t) mk_(u32, uint32_t) mk_(i64, int64_t) mk_(u64, uint64_t) mk_(isz, ssize_t) mk_(usz, size_t) mk_(chr, char) mk_(schr, signed char) mk_(uchr, unsigned char) mk_(sint, signed) mk_(uint, unsigned);
mk0_(i128, __int128_t); mk0_(u128, __uint128_t); mk0_(f32, float); mk0_(f64, double); mk0_(f128, long double);
#undef mk0_
#undef mk_

}  // namespace tifa_libs
// clang-format on
#line 4 "src/util/consts/lib.hpp"
// clang-format off
namespace tifa_libs {
using std::numbers::pi_v;
template <std::floating_point FP>
inline FP eps_v = std::sqrt(std::numeric_limits<FP>::epsilon());
template <std::floating_point FP>
CEXP void set_eps(FP v) NE { eps_v<FP> = v; }
CEXP u32 TIME = ((__TIME__[0] & 15) << 20) | ((__TIME__[1] & 15) << 16) | ((__TIME__[3] & 15) << 12) | ((__TIME__[4] & 15) << 8) | ((__TIME__[6] & 15) << 4) | (__TIME__[7] & 15);
CEXP auto STR2U16 = [] { std::array<u32, 65536> table{}; table.fill(-1_u32); flt_ (u32, i, 48, 58) flt_ (u32, j, 48, 58) table[i << 8 | j] = (j & 15) * 10 + (i & 15); return table; }();

inline const auto fn_0 = [](auto&&...) NE {};
inline const auto fn_is0 = [](auto x) NE { return x == 0; };
}  // namespace tifa_libs
// clang-format on
#line 4 "src/util/alias/others/lib.hpp"

namespace tifa_libs {

template <class T>
struct chash {
  CEXP static u64 C = u64(pi_v<f128> * 2e18) | 71;
  CEXP u64 operator()(T x) CNE { return __builtin_bswap64(((u64)x ^ TIME) * C); }
};
// clang-format off
#define mk_(w, t) using w = t; using c##w = const t;
mk_(strn, std::string) mk_(strnv, std::string_view)
#undef mk_
template <class T> struct edge_t { T w; u32 u, v; CEXP auto operator<=>(edge_t CR) const = default; }; template <class T> using cedge_t = const edge_t<T>;
template <class T> struct pt3 { T _0, _1, _2; CEXP auto operator<=>(pt3 CR) const = default; }; template <class T> using cpt3 = const pt3<T>;
template <class T> struct pt4 { T _0, _1, _2, _3; CEXP auto operator<=>(pt4 CR) const = default; }; template <class T> using cpt4 = const pt4<T>;
#define mkT_(w, t, ...) template <class T> using w = t __VA_OPT__(, ) __VA_ARGS__; template <class T> using c##w = const t __VA_OPT__(, ) __VA_ARGS__;
mkT_(ptt, std::pair<T, T>) mkT_(alc, std::pmr::polymorphic_allocator<T>) mkT_(vec, std::vector<T>) mkT_(vvec, vec<vec<T>>) mkT_(v3ec, vvec<vec<T>>) mkT_(vecpt, vec<ptt<T>>) mkT_(vvecpt, vvec<ptt<T>>) mkT_(ptvec, ptt<vec<T>>) mkT_(ptvvec, ptt<vvec<T>>)
#undef mkT_
template <class T> using itl = std ::initializer_list<T>;
template <class T, usz ext = std::dynamic_extent> using spn = std::span<T const, ext>;
template <class T, usz N> using arr = std::array<T, N>; template <class T, usz N> using carr = std::array<const T, N>;
template <class U, class T> using vecp = vec<std::pair<U, T>>; template <class U, class T> using vvecp = vvec<std::pair<U, T>>;
template <class U, class T> using vvecp = vvec<std::pair<U, T>>; template <class U, class T> using vvvecp = vvec<vvec<std::pair<U, T>>>;
#ifdef PB_DS_ASSOC_CNTNR_HPP
template <class T, class C = std::less<T>> using set = __gnu_pbds::tree<T, __gnu_pbds::null_type, C>;
template <class K, class V, class C = std::less<K>> using map = __gnu_pbds::tree<K, V, C>;
// hset<u64> s({}, {}, {}, {}, {1<<16});
template <class T, class HF = chash<T>> using hset = __gnu_pbds::gp_hash_table<T, __gnu_pbds::null_type, HF>;
// hmap<u64, int> s({}, {}, {}, {}, {1<<16});
template <class K, class V, class HF = chash<K>> using hmap = __gnu_pbds::gp_hash_table<K, V, HF>;
#else
using std::set, std::map;
template <class T, class HF = chash<T>> using hset = std::unordered_set<T, HF>;
template <class K, class V, class HF = chash<K>> using hmap = std::unordered_map<K, V, HF>;
#endif
#ifdef PB_DS_PRIORITY_QUEUE_HPP
template <class T, class C = std::less<T>> using pq = __gnu_pbds::priority_queue<T, C>;
#else
template <class T, class C = std::less<T>> using pq = std::priority_queue<T, vec<T>, C>;
#endif
template <class T> using pqg = pq<T, std::greater<T>>;
// clang-format on
#define mk1_(V, A, T) using V##A = V<T>;
#define mk_(V, A, T) mk1_(V, A, T) mk1_(c##V, A, T)
#define mk(A, T) mk_(edge_t, A, T) mk_(ptt, A, T) mk_(pt3, A, T) mk_(pt4, A, T) mk_(vec, A, T) mk_(vvec, A, T) mk_(v3ec, A, T) mk_(vecpt, A, T) mk_(vvecpt, A, T) mk_(ptvec, A, T) mk_(ptvvec, A, T) mk1_(spn, A, T) mk1_(itl, A, T)
mk(b, bool) mk(c, chr) mk(i, i32) mk(u, u32) mk(ii, i64) mk(uu, u64) mk(t, isz) mk(z, usz) mk(f, f32) mk(d, f64) mk(s, strn);
#undef mk
#undef mk_
#undef mk1_

}  // namespace tifa_libs
#line 2 "src/util/traits/math/lib.hpp"
// clang-format off
#line 4 "src/util/traits/math/lib.hpp"

namespace tifa_libs {

template <class T> concept char_c = std::same_as<T, char> || std::same_as<T, signed char> || std::same_as<T, unsigned char>;
#pragma GCC diagnostic ignored "-Wpedantic"
template <class T> concept s128_c = std::same_as<T, __int128_t> || std::same_as<T, __int128>;
template <class T> concept u128_c = std::same_as<T, __uint128_t> || std::same_as<T, unsigned __int128>;
template <class T> concept i128_c = s128_c<T> || u128_c<T>;
#pragma GCC diagnostic warning "-Wpedantic"
template <class T> concept imost64_c = std::integral<T> && sizeof(T) * __CHAR_BIT__ <= 64;
template <class T> concept smost64_c = imost64_c<T> && std::signed_integral<T>;
template <class T> concept umost64_c = imost64_c<T> && std::unsigned_integral<T>;
template <class T> concept int_c = i128_c<T> || imost64_c<T>;
template <class T> concept sint_c = s128_c<T> || smost64_c<T>;
template <class T> concept uint_c = u128_c<T> || umost64_c<T>;
template <class T> concept arithm_c = std::is_arithmetic_v<T> || int_c<T>;
template <class T> concept mint_c = requires(T x) { {x.mod()} -> uint_c; {x.val()} -> uint_c; };
template <class T> concept dft_c = requires(T x, std::vector<TPN T::data_t> v, u32 n) { {x.size()} -> std::same_as<u32>; x.bzr(n); x.dif(v, n); x.dit(v, n); };
template <class T> concept ntt_c = dft_c<T> && requires(T x) { T::max_size; T::G; };

template <class T> struct to_sint : std::make_signed<T> {};
template <> struct to_sint<u128> { using type = i128; };
template <> struct to_sint<i128> { using type = i128; };
template <class T> using to_sint_t = TPN to_sint<T>::type;
template <class T> struct to_uint : std::make_unsigned<T> {};
template <> struct to_uint<u128> { using type = u128; };
template <> struct to_uint<i128> { using type = u128; };
template <class T> using to_uint_t = TPN to_uint<T>::type;
template <arithm_c T> struct to_bigger : std::make_unsigned<T> {};
#define _(w,ww) template <> struct to_bigger<w> { using type = ww; }
#define _2(w,ww) _(i##w,i##ww); _(u##w,u##ww);
_2(8, 16); _2(16, 32); _2(32, 64); _2(64, 128); _(f32, f64); _(f64, f128);
#undef _2
#undef _
template <class T> using to_bigger_t = TPN to_bigger<T>::type;

template <arithm_c T> CEXP T inf_v = [] {
    if CEXP(sint_c<T>) return T(to_uint_t<T>(-1) / 4 - 1);
    else if CEXP(uint_c<T>) return T(-1) / 2 - 1;
    else return std::numeric_limits<T>::max() / 2 - 1;
}();

}  // namespace tifa_libs
// clang-format on
#line 5 "src/io/fastin/lib.hpp"
#ifdef __linux__
#include <sys/mman.h>
#include <sys/stat.h>
#endif

namespace tifa_libs {

struct fastin_data {
  CEXP static u32 BUF = 0x200005;
  FILE* f_ = nullptr;
#ifdef __linux__
  chr *bg, *ed, *p;
  struct stat Fl;

  void rebind(FILE* f = nullptr) NE {
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
    if (!f_) munmap(bg, Fl.st_size + 1);
#pragma GCC diagnostic warning "-Wmaybe-uninitialized"
    if (!f) return;
    auto fd = fileno(f_ = f);
    fstat(fd, &Fl);
    p = (bg = (chr*)mmap(nullptr, Fl.st_size + 4, PROT_READ, MAP_PRIVATE, fd, 0));
    ed = bg + Fl.st_size;
    madvise(bg, Fl.st_size + 4, MADV_SEQUENTIAL);
  }

  ND bool iseof() CNE { return p == ed; }
  ~fastin_data() NE { rebind(); }
#else
  // NOLINTNEXTLINE(modernize-avoid-c-arrays)
  chr buf[BUF], *ed, *p;

  void rebind(FILE* f) NE { f_ = f, p = ed = buf; }
  ND bool iseof() NE {
    if (p == ed) [[unlikely]]
      ed = (p = buf) + fread(buf, 1, BUF, f_);
    return p == ed;
  }
#endif

  fastin_data(FILE* f = stdin) NE { assert(f), rebind(f); }
  fastin_data(fastin_data CR) = delete;
  fastin_data& operator=(fastin_data CR) = delete;
};
// clang-format off
enum FIN_SET : u8 { FS_NEWLINE = 1, FS_SPACE = 2, FS_NEG = 4, FS_NUM = 8, FS_ALPHA = 16, FS_OTHERS = 32 };
// clang-format on
template <u32 charset>
class fastin {
  fastin_data& data;

  static CEXP bool is_cntrl(chr c) NE {
    if CEXP (charset & FS_OTHERS) return iscntrl(c);
    else if CEXP (charset & FS_NEWLINE) return c < 32;
    else return false;
  }
  static CEXP bool is_cntrls(chr c) NE {
    if CEXP (charset & FS_OTHERS) return !isgraph(c);
    else if CEXP (charset & (FS_NEWLINE | FS_SPACE)) return c <= 32;
    else return false;
  }
  static CEXP bool is_digit(chr c) NE {
    if CEXP (charset & (FS_ALPHA | FS_OTHERS)) return isdigit(c);
    else if CEXP (!(charset & FS_NUM)) return false;
    else if CEXP (!(charset & FS_NEG)) return c > 32;
    else return c >= 48;
  }
  static CEXP bool is_neg_digit(chr c) NE {
    if CEXP (!(charset & FS_NEG)) return is_digit(c);
    else if CEXP (charset & (FS_ALPHA | FS_OTHERS)) return c == '-' || isdigit(c);
    else return c > 32;
  }
#ifdef __linux__
  template <bool ignore_space = true>
  void read_str(strn& n) NE {
    chr* l;
    if CEXP (ignore_space) {
      skip_cntrls(), l = data.p;
      while (!is_cntrls(*data.p)) ++data.p;
    } else {
      skip_cntrl(), l = data.p;
      while (!is_cntrl(*data.p)) ++data.p;
    }
    n.assign(l, data.p);
  }
#else
  template <bool ignore_space>
  void read_str(strn& n) NE {
    if CEXP (n.clear(); ignore_space) {
      n.push_back(skip_cntrls().get());
      while (!is_cntrls(peek())) n.push_back(get());
    } else {
      n.push_back(skip_cntrl().get());
      while (!is_cntrl(peek())) n.push_back(get());
    }
  }
#endif
 public:
  fastin(fastin_data& data) NE : data(data) {}
  fastin(fastin CR) = delete;
  fastin& operator=(fastin CR) = delete;

  chr peek() NE {
    if (data.iseof()) [[unlikely]]
      return EOF;
    return *data.p;
  }
  chr get_unchk() NE { return *data.p++; }
  chr get() NE {
    if (data.iseof()) [[unlikely]]
      return EOF;
    return get_unchk();
  }
#define SKIP(name, pred)              \
  fastin& skip_##name() NE {          \
    while (pred(peek())) get_unchk(); \
    return *this;                     \
  }
  SKIP(cntrl, is_cntrl)
  SKIP(cntrls, is_cntrls)
  SKIP(ndigit, !is_digit)
  SKIP(nnegdigit, !is_neg_digit)
#undef SKIP
  template <class T>
  requires(imost64_c<T> && !char_c<T>)
  fastin& operator>>(T& n) NE {
    if CEXP (std::same_as<T, bool>) n = skip_ndigit().get() != '0';
    else {
      n = 0;
      bool is_neg = false;
      if CEXP ((charset & FS_NEG) && std::signed_integral<T>) is_neg = (skip_nnegdigit().peek() == '-' && get_unchk());
      else skip_ndigit();
      std::conditional_t<sizeof(T) < sizeof(u32), u32, to_uint_t<T>> n_ = 0;
#ifdef __linux__
      // clang-format off
#define _ {while (~STR2U16[*(u16*)data.p]) (n_ *= 100) += STR2U16[*(u16*)data.p], data.p += 2; if (is_digit(peek())) (n_ *= 10) += get_unchk() & 15;}
      if ((usz)data.p & 1) { if (is_digit(peek())) [[likely]] { (n_ *= 10) += get_unchk() & 15; _ } } else _;
#undef _
      // clang-format on
#else
      while (is_digit(peek())) (n_ *= 10) += get_unchk() & 15;
#endif
      if CEXP (sint_c<T>)
        if (is_neg) n_ = -n_;
      n = (T)n_;
    }
    return *this;
  }
  fastin& operator>>(std::floating_point auto& n) NE {
    static strn s;
    (*this >> s), std::from_chars(begin(s).base(), end(s).base(), n);
    return *this;
  }
  //! ignore cntrl and space
  fastin& operator>>(char_c auto& n) NE {
    n = skip_cntrls().get();
    return *this;
  }
  fastin& operator>>(strn& n) NE {
    read_str<true>(n);
    return *this;
  }
  fastin& getline(strn& n) NE {
    read_str<false>(n);
    return *this;
  }
  //! NOT ignore cntrl and space
  fastin& strict_read(char_c auto& n) NE {
    n = get();
    return *this;
  }
  fastin& operator>>(fastin& (*func)(fastin&)) NE { return func(*this); }
};
inline fastin_data fid_stdin;
inline fastin<FS_NEWLINE | FS_SPACE | FS_NEG | FS_NUM | FS_ALPHA | FS_OTHERS> fin(fid_stdin);
inline fastin<FS_NEWLINE | FS_SPACE | FS_NEG | FS_NUM> fin_int(fid_stdin);
inline fastin<FS_NEWLINE | FS_SPACE | FS_NUM> fin_uint(fid_stdin);
template <u32 w>
inline fastin<w>& ws(fastin<w>& f) NE { return f.skip_cntrls(); }

}  // namespace tifa_libs
#line 2 "src/io/fastout/lib.hpp"

#line 5 "src/io/fastout/lib.hpp"

namespace tifa_libs {

class fastout {
  CEXP static u32 BUF = 0x200005, INTBUF = 63;
  FILE* f_ = nullptr;
  // NOLINTNEXTLINE(modernize-avoid-c-arrays)
  chr int_buf[INTBUF];
  // NOLINTNEXTLINE(modernize-avoid-c-arrays)
  chr buf[BUF], *p;
  chr CPC ed = buf + BUF;
  std::chars_format fmt = std::chars_format::general;
  int precision = 6;

  fastout& write_str(chr CP n, usz len = 0) NE {
    if (!len) len = strlen(n);
    usz l_;
    chr CP n_ = n;
    while (p + len >= ed) memcpy(p, n_, l_ = usz(ed - p)), p += l_, n_ += l_, len -= l_, flush();
    return memcpy(p, n_, len), p += len, *this;
  }

 public:
  fastout(FILE* f = stdout) NE { rebind(f); }
  fastout(fastout CR) = delete;
  fastout& operator=(fastout CR) = delete;
  ~fastout() NE { flush(); }
  void rebind(FILE* f) NE { f_ = f, p = buf; }
  void flush() NE { fwrite(buf, 1, usz(p - buf), f_), p = buf; }
  fastout& operator<<(char_c auto n) NE {
    if (p == ed) [[unlikely]]
      flush();
    *(p++) = n;
    return *this;
  }
  fastout& operator<<(chr CP n) NE { return write_str(n); }
  fastout& operator<<(strn CR str) NE { return write_str(str.data(), str.size()); }
  fastout& operator<<(strnv str) NE { return write_str(str.data(), str.size()); }
  template <class T>
  requires(smost64_c<T> && !char_c<T>)
  fastout& operator<<(T n) NE {
    if CEXP (sizeof(T) < sizeof(i32)) return *this << (i32)n;
    else {
      if (n < 0) return *this << '-' << -to_uint_t<T>(n);
      return *this << to_uint_t<T>(n);
    }
  }
  template <class T>
  requires(umost64_c<T> && !char_c<T>)
  fastout& operator<<(T n) NE {
    if CEXP (std::same_as<T, bool>) return *this << (chr(n | '0'));
    else if CEXP (sizeof(T) < sizeof(u32)) return *this << (u32)n;
    else if (usz(p - buf) >= BUF - INTBUF) [[unlikely]] {
      auto res = std::to_chars(int_buf, int_buf + INTBUF, n);
      return write_str(int_buf, usz(res.ptr - int_buf));
    } else {
      auto res = std::to_chars(p, buf + BUF, n);
      p = res.ptr;
      return *this;
    }
  }
  fastout& operator<<(std::floating_point auto n) NE {
    if (usz(p - buf) >= BUF - INTBUF) [[unlikely]] {
      auto res = std::to_chars(int_buf, int_buf + INTBUF, n, fmt, precision);
      return write_str(int_buf, usz(res.ptr - int_buf));
    } else {
      auto res = std::to_chars(p, buf + BUF, n, fmt, precision);
      p = res.ptr;
      return *this;
    }
  }
  fastout& setf(std::chars_format f) NE {
    fmt = f;
    return *this;
  }
  //! only tested in libstdc++
  fastout& operator<<(decltype(std::setprecision(0)) p) NE {
    precision = *(int*)(&p);
    return *this;
  }
  fastout& operator<<(fastout& (*func)(fastout&)) NE { return func(*this); }
};
inline fastout fout;
inline fastout& scientific(fastout& f) NE { return f.setf(std::chars_format::scientific); }
inline fastout& fixed(fastout& f) NE { return f.setf(std::chars_format::fixed); }
inline fastout& hexfloat(fastout& f) NE { return f.setf(std::chars_format::hex); }
inline fastout& defaultfloat(fastout& f) NE { return f.setf(std::chars_format::general); }
inline fastout& endl(fastout& f) NE {
  (f << '\n').flush();
  return f;
}
using std::setprecision;

}  // namespace tifa_libs
#line 2 "src/nt/pfactors/lib.hpp"

#line 2 "src/edh/discretization/lib.hpp"

#line 2 "src/fast/rsort32/lib.hpp"

#line 4 "src/fast/rsort32/lib.hpp"

namespace tifa_libs {

template <class C>
requires(std::is_array_v<C> && std::integral<decltype(std::declval<C>()[0])> && sizeof(std::declval<C>()[0]) == 4) || (std::contiguous_iterator<TPN C::iterator> && std::integral<TPN C::value_type> && sizeof(TPN C::value_type) == 4)
void rsort32(C& a) NE {
  if (a.size() <= 1) return;
  if (a.size() <= 200'000) {
    std::ranges::sort(a);
    return;
  }
  arr<u32, 256> _0{}, _1{}, _2{}, _3{};
  cu32 n = (u32)a.size();
  vecu b(n);
  u32 *a_ = (u32*)a.data(), *b_ = (u32*)b.data();
  for (cu32 *_ = a_ + n, *i = a_; i < _; ++i) ++_0[*i & 255], ++_1[*i >> 8 & 255], ++_2[*i >> 16 & 255], ++_3[*i >> 24 & 255];
  flt_ (u32, i, 1, 256) _0[i] += _0[i - 1], _1[i] += _1[i - 1], _2[i] += _2[i - 1], _3[i] += _3[i - 1];
  for (u32 CP i = a_ + n; --i >= a_;) b_[--_0[*i & 255]] = *i;
  for (u32 CP i = b_ + n; --i >= b_;) a_[--_1[*i >> 8 & 255]] = *i;
  for (u32 CP i = a_ + n; --i >= a_;) b_[--_2[*i >> 16 & 255]] = *i;
  for (u32 CP i = b_ + n; --i >= b_;) a_[--_3[*i >> 24 & 255]] = *i;
  if CEXP (std::is_signed_v<TPN C::value_type>) {
    u32 i = n;
    while (i && a[i - 1] < 0) --i;
    rotate(a_, a_ + n, a_ + i);
  }
}
template <class C>
requires(std::is_array_v<C> && std::integral<decltype(std::declval<C>()[0])> && sizeof(std::declval<C>()[0]) == 4) || range<C>
void sort(C& a) NE {
  if CEXP (std::is_array_v<C> || (std::contiguous_iterator<TPN C::iterator> && std::integral<TPN C::value_type> && sizeof(TPN C::value_type) == 4)) rsort32(a);
  else std::ranges::sort(a);
}

}  // namespace tifa_libs
#line 4 "src/edh/discretization/lib.hpp"

namespace tifa_libs {

template <common_range T>
CEXP T uniq(T v) NE {
  tifa_libs::sort(v);
  auto r = unique(begin(v), end(v));
  return {begin(v), begin(r)};
}
template <common_range T>
CEXP std::pair<T, vecu> gen_id(T CR v) NE {
  const T _ = uniq(v);
  vecu _1;
  _1.reserve(v.size());
  flt_ (u32, i, 0, (u32)v.size()) _1.push_back(u32(lower_bound(_, v[i]) - begin(_)));
  return {_, _1};
}

}  // namespace tifa_libs
#line 2 "src/math/mul_mod/lib.hpp"

#line 2 "src/math/safe_mod/lib.hpp"

#line 4 "src/math/safe_mod/lib.hpp"

namespace tifa_libs {

template <int_c T>
CEXP T safe_mod(T x, to_uint_t<T> mod) NE {
  if CEXP (sint_c<T>) {
    if (x <= -(T)mod || x >= (T)mod) x %= (T)mod;
    retif_((x < 0), x + (T)mod, x);
  } else {
    retif_((x >= mod), x % mod, x);
  }
}

}  // namespace tifa_libs
#line 4 "src/math/mul_mod/lib.hpp"

namespace tifa_libs {

CEXP i64 mul_mod_s(i64 a, i64 b, u64 mod) NE {
  if (std::bit_width((u64)abs(a)) + std::bit_width((u64)abs(b)) < 64) return safe_mod(a * b % (i64)mod, mod);
  return safe_mod((i64)((i128)a * b % mod), mod);
}
CEXP u64 mul_mod_u(u64 a, u64 b, u64 mod) NE {
  if (std::bit_width(a) + std::bit_width(b) <= 64) return a * b % mod;
  return (u64)((u128)a * b % mod);
}

}  // namespace tifa_libs
#line 2 "src/util/rand/lib.hpp"

#line 5 "src/util/rand/lib.hpp"

namespace tifa_libs {

template <class T>
requires std::is_arithmetic_v<T>
class rand_gen {
  using res_t = std::conditional_t<sizeof(T) <= 4, u32, u64>;
  using res_wt = std::conditional_t<sizeof(T) <= 4, u64, u128>;
  // clang-format off
  struct mt19937_param { static CEXP u32 w = 32, n = 624, m = 397, r = 31, a = 0x9908b0df, u = 11, d = 0xffffffff, s = 7, b = 0x9d2c5680, t = 15, c = 0xefc60000, l = 18, f = 1812433253; };
  struct mt19937_64_param { static CEXP u64 w = 64, n = 312, m = 156, r = 31, a = 0xb5026f5aa96619e9, u = 29, d = 0x5555555555555555, s = 17, b = 0x71d67fffeda60000, t = 37, c = 0xfff7eee000000000, l = 43, f = 6364136223846793005; };
  using pm = std::conditional_t<std::is_same_v<res_t, u32>, mt19937_param, mt19937_64_param>;
  // clang-format on
  T a_, b_;

  arr<res_t, pm::n> x_;
  u32 p_;
  CEXP void gen_() NE {
    CEXP res_t um = (~res_t()) << pm::r, lm = ~um;
    res_t _;
    flt_ (res_t, i, p_ = 0, pm::n - pm::m) _ = ((x_[i] & um) | (x_[i + 1] & lm)), x_[i] = (x_[i + pm::m] ^ (_ >> 1) ^ ((_ & 1) ? pm::a : 0));
    flt_ (res_t, i, pm::n - pm::m, pm::n - 1) _ = ((x_[i] & um) | (x_[i + 1] & lm)), x_[i] = (x_[i + (pm::m - pm::n)] ^ (_ >> 1) ^ ((_ & 1) ? pm::a : 0));
    _ = ((x_[pm::n - 1] & um) | (x_[0] & lm)), x_[pm::n - 1] = (x_[pm::m - 1] ^ (_ >> 1) ^ ((_ & 1) ? pm::a : 0));
  }

 public:
  CEXPE rand_gen(T a = std::numeric_limits<T>::min(), T b = std::numeric_limits<T>::max(), res_t sd = (res_t)TIME) NE : a_(a), b_(b) { assert(a < b || (std::is_integral_v<T> && a == b)), seed(sd); }

  CEXP void range(T min, T max) NE { assert(min < max || (std::is_integral_v<T> && min == max)), a_ = min, b_ = max; }
  void seed() NE { seed((res_t)std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count()); }
  CEXP void seed(res_t sd) NE {
    x_[0] = sd & gen_max();
    flt_ (res_t, i, 1, p_ = pm::n) x_[i] = ((x_[i - 1] ^ (x_[i - 1] >> (pm::w - 2))) * pm::f + i % pm::n) & gen_max();
  }
  ND CEXP res_t gen_min() CNE { return 0; }
  ND CEXP res_t gen_max() CNE {
    if CEXP (sizeof(res_t) * 8 == pm::w) return ~res_t();
    else return ((res_t)1 << pm::w) - 1;
  }
  CEXP res_t next() NE {
    if (p_ >= pm::n) gen_();
    res_t _ = x_[p_++];
    _ ^= (_ >> pm::u) & pm::d, _ ^= (_ << pm::s) & pm::b, _ ^= (_ << pm::t) & pm::c, _ ^= (_ >> pm::l);
    return _;
  }
  CEXP T operator()() NE {
    if CEXP (std::integral<T>) {
      const res_wt r = (res_wt)b_ - (res_wt)a_ + 1;
      res_wt p = r * next();
      if (auto l = (res_t)p, _ = res_t(res_wt(-(res_t)r) % r); l < r)
        while (l < _) l = res_t(p = r * next());
      return T((res_t)(p >> pm::w) + (res_t)a_);
    } else return T(next() / (f128)((u128)gen_max() + 1) * (b_ - a_) + a_);
  }
};

}  // namespace tifa_libs
#line 2 "src/nt/gl/gcd/lib.hpp"

#line 4 "src/nt/gl/gcd/lib.hpp"

namespace tifa_libs {

namespace gcd_impl_ {
template <uint_c T, uint_c U>
CEXP std::common_type_t<T, U> gcd__(T u, U v) NE {
  using W = std::common_type_t<T, U>;
  retif_((!u || !v) [[unlikely]], u ^ v);
  const auto k = std::__countr_zero(u | v);
  u >>= k, v >>= k;
  do {
    if (W const _ = v >> std::__countr_zero(v); u > _) v = u - _, u = _;
    else v = _ - u;
  } while (v);
  return u << k;
}
}  // namespace gcd_impl_

template <int_c T, int_c U>
CEXP auto gcd(T a, U b) NE { return gcd_impl_::gcd__((to_uint_t<T>)abs(a), (to_uint_t<U>)abs(b)); }

}  // namespace tifa_libs
#line 2 "src/nt/is_prime/lib.hpp"

#line 2 "src/math/qpow/mod/lib.hpp"

#line 4 "src/math/qpow/mod/lib.hpp"

namespace tifa_libs {

CEXP u64 qpow_mod(u64 a, u64 b, u64 mod) NE {
  u64 res(1);
  for (a %= mod; b; b >>= 1, a = mul_mod_u(a, a, mod)) {
    while (!(b & 1)) b >>= 1, a = mul_mod_u(a, a, mod);
    res = mul_mod_u(res, a, mod);
  }
  return res;
}

}  // namespace tifa_libs
#line 5 "src/nt/is_prime/lib.hpp"

namespace tifa_libs {

CEXP bool is_prime(u64 n) NE {
  retif_((n <= 2) [[unlikely]], n == 2);
  if (~n & 1) return false;
  if (n < 8 || n == 61) return true;
  if (!(n % 3) || !(n % 5) || !(n % 7)) return false;
  if (n < 121) return true;
  auto f = [n, d = (n - 1) >> std::countr_zero(n - 1)](auto&& bases) NE -> bool {
    for (cu64 i : bases) {
      if (!(i % n)) continue;
      u64 t = d, y = qpow_mod(i, t, n);
      while (t != n - 1 && y != 1 && y != n - 1) y = mul_mod_u(y, y, n), t *= 2;
      if (y != n - 1 && (~t & 1)) return false;
    }
    return true;
  };
  // NOLINTBEGIN(modernize-avoid-c-arrays)
  CEXP u64 THRES1 = 341531, BASE1[]{9345883071009581737u};
  CEXP u64 THRES2 = 1050535501, BASE2[]{336781006125, 9639812373923155};
  CEXP u64 THRES3 = 350269456337, BASE3[]{4230279247111683200, 14694767155120705706u, 16641139526367750375u};
  CEXP u64 THRES4 = 55245642489451, BASE4[]{2, 141889084524735, 1199124725622454117, 11096072698276303650u};
  CEXP u64 THRES5 = 7999252175582851, BASE5[]{2, 4130806001517, 149795463772692060, 186635894390467037, 3967304179347715805};
  CEXP u64 THRES6 = 585226005592931977, BASE6[]{2, 123635709730000, 9233062284813009, 43835965440333360, 761179012939631437, 1263739024124850375};
  CEXP u64 BASE7[]{2, 325, 9375, 28178, 450775, 9780504, 1795265022};
  // NOLINTEND(modernize-avoid-c-arrays)
  if (n < THRES1) return f(BASE1);
  if (n < THRES2) return f(BASE2);
  if (n < THRES3) return f(BASE3);
  if (n < THRES4) return f(BASE4);
  if (n < THRES5) return f(BASE5);
  if (n < THRES6) return f(BASE6);
  return f(BASE7);
}

}  // namespace tifa_libs
#line 8 "src/nt/pfactors/lib.hpp"

namespace tifa_libs {
namespace pfactors_impl_ {
static rand_gen<u64> e;
static auto __ = [] { e.seed(); return 0; }();
CEXP u64 rho(u64 n) NE {
  e.range(1, n - 1);
  auto f = [n, r = e()](u64 x) NE { return (mul_mod_u(x, x, n) + r) % n; };
  u64 g = 1, x = 0, y = e(), yy = 0;
  cu32 LIM = 128;
  for (u64 r = 1, q = 1; g == 1; r *= 2) {
    x = y;
    flt_ (u64, i, 0, r) y = f(y);
    for (u64 k = 0; g == 1 && k < r; k += LIM) {
      yy = y;
      for (u64 i = 0; i < LIM && i < r - k; ++i) q = mul_mod_u(q, (n - (y = f(y)) + x) % n, n);
      g = gcd(q, n);
    }
  }
  if (g == n) do {
      g = gcd((x + (n - (yy = f(yy)))) % n, n);
    } while (g == 1);
  retif_((g == n), rho(n), g);
}
CEXP void run(u64 n, vecuu& p) NE {
  if (n < 2) return;
  if (is_prime(n)) return p.push_back(n);
  cu64 g = rho(n);
  run(n / g, p), run(g, p);
}
}  // namespace pfactors_impl_

template <bool unique = true>
CEXP vecuu pfactors(u64 n) NE {
  vecuu p;
  if (cu32 _ = (u32)std::countr_zero(n) & 63; _) {
    n >>= _;
    if CEXP (unique) p.push_back(2);
    else p.assign(_, 2);
  }
  if (n < 1000'000)
    for (u32 i = 3; i <= n; ++i) {
      if (n % i) continue;
      if CEXP (unique) p.push_back(i);
      do {
        if CEXP (n /= i; !unique) p.push_back(i);
      } while (!(n % i));
    }
  if (n < 2) return p;
  pfactors_impl_::run(n, p);
  if CEXP (unique) return uniq(p);
  tifa_libs::sort(p);
  return p;
}
CEXP vecp<u64, u32> pf_exp(u64 n) NE {
  auto p = pfactors<false>(n);
  vecp<u64, u32> ans;
  for (u64 lst = 0; cu64 i : p)
    if (i != lst) ans.emplace_back(lst = i, 1);
    else ++ans.back().second;
  return ans;
}

}  // namespace tifa_libs
#line 5 "test/cpv/aizu-ntl/ntl_1_a.cpp"

using namespace tifa_libs;
int main() {
  u64 n;
  fin_uint >> n;
  auto ans = pfactors<false>(n);
  fout << n << ":";
  for (auto k : ans) fout << ' ' << k;
  fout << '\n';
  return 0;
}

Test cases

Env Name Status Elapsed Memory
verify-g++ 00_small_00 :heavy_check_mark: AC 10 ms 20 MB
verify-g++ 00_small_01 :heavy_check_mark: AC 10 ms 20 MB
verify-g++ 00_small_02 :heavy_check_mark: AC 9 ms 20 MB
verify-g++ 00_small_03 :heavy_check_mark: AC 10 ms 20 MB
verify-g++ 01_medium_00 :heavy_check_mark: AC 9 ms 20 MB
verify-g++ 01_medium_01 :heavy_check_mark: AC 9 ms 20 MB
verify-g++ 01_medium_02 :heavy_check_mark: AC 9 ms 22 MB
verify-g++ 01_medium_03 :heavy_check_mark: AC 9 ms 20 MB
verify-g++ 01_medium_04 :heavy_check_mark: AC 9 ms 20 MB
verify-g++ 01_medium_05 :heavy_check_mark: AC 9 ms 20 MB
verify-g++ 02_large_00 :heavy_check_mark: AC 9 ms 20 MB
verify-g++ 02_large_01 :heavy_check_mark: AC 9 ms 20 MB
verify-g++ 02_large_02 :heavy_check_mark: AC 10 ms 20 MB
verify-g++ 02_large_03 :heavy_check_mark: AC 10 ms 20 MB
verify-g++ 02_large_04 :heavy_check_mark: AC 9 ms 22 MB
verify-g++ 02_large_05 :heavy_check_mark: AC 10 ms 22 MB
verify-g++ 02_large_06 :heavy_check_mark: AC 10 ms 20 MB
verify-g++ 02_large_07 :heavy_check_mark: AC 9 ms 20 MB
verify-g++ 03_critical_00 :heavy_check_mark: AC 10 ms 22 MB
verify-g++ 03_critical_01 :heavy_check_mark: AC 10 ms 20 MB
verify-g++ 03_critical_02 :heavy_check_mark: AC 10 ms 22 MB
verify-g++ 03_critical_03 :heavy_check_mark: AC 10 ms 22 MB
verify-g++ 03_critical_04 :heavy_check_mark: AC 10 ms 22 MB
verify-g++ 03_critical_05 :heavy_check_mark: AC 9 ms 22 MB
coverage-g++ 00_small_00 :heavy_check_mark: AC 3 ms 4 MB
coverage-g++ 00_small_01 :heavy_check_mark: AC 2 ms 4 MB
coverage-g++ 00_small_02 :heavy_check_mark: AC 2 ms 4 MB
coverage-g++ 00_small_03 :heavy_check_mark: AC 2 ms 4 MB
coverage-g++ 01_medium_00 :heavy_check_mark: AC 2 ms 4 MB
coverage-g++ 01_medium_01 :heavy_check_mark: AC 2 ms 4 MB
coverage-g++ 01_medium_02 :heavy_check_mark: AC 2 ms 4 MB
coverage-g++ 01_medium_03 :heavy_check_mark: AC 2 ms 4 MB
coverage-g++ 01_medium_04 :heavy_check_mark: AC 2 ms 4 MB
coverage-g++ 01_medium_05 :heavy_check_mark: AC 2 ms 4 MB
coverage-g++ 02_large_00 :heavy_check_mark: AC 2 ms 4 MB
coverage-g++ 02_large_01 :heavy_check_mark: AC 2 ms 4 MB
coverage-g++ 02_large_02 :heavy_check_mark: AC 2 ms 4 MB
coverage-g++ 02_large_03 :heavy_check_mark: AC 2 ms 4 MB
coverage-g++ 02_large_04 :heavy_check_mark: AC 2 ms 4 MB
coverage-g++ 02_large_05 :heavy_check_mark: AC 2 ms 4 MB
coverage-g++ 02_large_06 :heavy_check_mark: AC 2 ms 4 MB
coverage-g++ 02_large_07 :heavy_check_mark: AC 2 ms 4 MB
coverage-g++ 03_critical_00 :heavy_check_mark: AC 2 ms 4 MB
coverage-g++ 03_critical_01 :heavy_check_mark: AC 2 ms 4 MB
coverage-g++ 03_critical_02 :heavy_check_mark: AC 2 ms 4 MB
coverage-g++ 03_critical_03 :heavy_check_mark: AC 2 ms 4 MB
coverage-g++ 03_critical_04 :heavy_check_mark: AC 2 ms 6 MB
coverage-g++ 03_critical_05 :heavy_check_mark: AC 2 ms 4 MB
Back to top page