1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#pragma once


#include <cassert><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <ranges><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.


#include "adaptor/vector.hpp"
#include "adaptor/set.hpp"
#include "adaptor/map.hpp"

#include "numeric/internal/primality_test.hpp"
#include "numeric/internal/factorize.hpp"
#include "numeric/internal/divisors.hpp"
#include "numeric/internal/primitive_root.hpp"
#include "numeric/modular/modint.hpp"


namespace uni {

namespace internal {


constexpr i64 INTERNAL_MODINT_ID = -(1L << 62);


inline constexpr bool is_prime(const i64 n) noexcept(NO_EXCEPT) {
    assert(n >= 0);
    return is_prime<uni::dynamic_montgomery_modint_32bit<INTERNAL_MODINT_ID>, uni::dynamic_montgomery_modint_64bit<INTERNAL_MODINT_ID>>(n);
}

inline auto factorize(const i64 n) noexcept(NO_EXCEPT) {
    assert(n >= 0);
    vector<i64> res;
    factorize<uni::dynamic_montgomery_modint_32bit<INTERNAL_MODINT_ID>, uni::dynamic_montgomery_modint_64bit<INTERNAL_MODINT_ID>>(n, &res);
    return res;
}

inline auto divisors(const i64 n) noexcept(NO_EXCEPT) {
    assert(n >= 0);
    vector<i64> res;
    divisors<uni::dynamic_montgomery_modint_32bit<INTERNAL_MODINT_ID>, uni::dynamic_montgomery_modint_64bit<INTERNAL_MODINT_ID>>(n, &res);
    std::ranges::sort(res);
    return res;
}

template<bool FORCE_RANDOM = false>
inline auto primitive_root(const i64 n) noexcept(NO_EXCEPT) {
    assert(n >= 0);
    return primitive_root<uni::dynamic_montgomery_modint_32bit<INTERNAL_MODINT_ID>, uni::dynamic_montgomery_modint_64bit<INTERNAL_MODINT_ID>, i64, FORCE_RANDOM>(n);
}


} // namespace internal


using internal::is_prime;
using internal::divisors;
using internal::primitive_root;


inline vector<i64> factorize(const i64 n) noexcept(NO_EXCEPT) {
    assert(n >= 0);
    auto res = internal::factorize(n);
    std::ranges::sort(res);
    return res;
}

inline set<i64> prime_factors(const i64 n) noexcept(NO_EXCEPT) {
    assert(n >= 0);
    const auto factors = factorize(n);
    set<i64> res(ALL(factors));
    return res;
}

inline map<i64,i64> count_factors(const i64 n) noexcept(NO_EXCEPT) {
    assert(n >= 0);
    map<i64,i64> mp;
    for(auto &x : internal::factorize(n)) mp[x]++;<--- Variable 'x' can be declared as reference to const
    return mp;
}


} // namespace uni