15template <
typename IntegralType, Traits::EnableIf<std::is_
integral<IntegralType>> * =
nullptr>
16constexpr IntegralType
digitsum(IntegralType number, IntegralType base = 10)
29template <
typename IntegralType, Traits::EnableIf<std::is_
integral<IntegralType>> * =
nullptr>
constexpr IntegralType
factorial(IntegralType number)
32 for (IntegralType
i = 1;
i <= number; ++
i) {
41template <
typename IntegralType, Traits::EnableIf<std::is_
integral<IntegralType>, std::is_
unsigned<IntegralType>> * =
nullptr>
42constexpr IntegralType
powerModulo(
const IntegralType base,
const IntegralType exponent,
const IntegralType module)
45 for (IntegralType mask =
static_cast<IntegralType
>(1) <<
static_cast<IntegralType
>(
sizeof(IntegralType) * 8 - 1); mask; mask >>= 1) {
46 if (mask & exponent) {
60template <
typename IntegralType, Traits::EnableIf<std::is_
integral<IntegralType>, std::is_
unsigned<IntegralType>> * =
nullptr>
61constexpr IntegralType
inverseModulo(IntegralType number, IntegralType module)
63 IntegralType y1 = 0, y2 = 1;
65 IntegralType tmp = y1 - (module / number) * y2;
68 tmp =
module % number;
78template <
typename IntegralType, Traits::EnableIf<std::is_
integral<IntegralType>, std::is_
unsigned<IntegralType>> * =
nullptr>
79constexpr IntegralType
orderModulo(
const IntegralType number,
const IntegralType module)
81 IntegralType order = 1;
82 for (;
powerModulo(number, order, module) != 1 && order !=
module; ++order)
84 return order !=
module ? order : 0;
88template <
typename T>
constexpr T
min(T first, T second)
90 return first < second ? first : second;
94template <
typename T1,
typename... T2>
constexpr T1
min(T1 first, T1 second, T2... remaining)
96 return first < second ?
min(first, remaining...) :
min(second, remaining...);
100template <
typename T>
constexpr T
max(T first, T second)
102 return first > second ? first : second;
106template <
typename T1,
typename... T2>
constexpr T1
max(T1 first, T1 second, T2... remaining)
108 return first > second ?
max(first, remaining...) :
max(second, remaining...);
Contains all utilities provides by the c++utilities library.
constexpr IntegralType factorial(IntegralType number)
Returns the factorial of the given number.
constexpr IntegralType inverseModulo(IntegralType number, IntegralType module)
Computes the inverse of number modulo module.
constexpr IntegralType digitsum(IntegralType number, IntegralType base=10)
Returns the digitsum of the given number using the specified base.
constexpr T max(T first, T second)
Returns the greatest of the given items.
constexpr IntegralType powerModulo(const IntegralType base, const IntegralType exponent, const IntegralType module)
Computes base power exponent modulo module.
constexpr T min(T first, T second)
Returns the smallest of the given items.
constexpr IntegralType orderModulo(const IntegralType number, const IntegralType module)
Computes the order of number modulo module.