1//! @file divisor.hpp
2//! @author ryftchen
3//! @brief The declarations (divisor) in the numeric module.
4//! @version 0.1.0
5//! @copyright Copyright (c) 2022-2025 ryftchen. All rights reserved.
6
7#pragma once
8
9#include <cstdint>
10#include <set>
11
12//! @brief The numeric module.
13namespace numeric // NOLINT(modernize-concat-nested-namespaces)
14{
15//! @brief Divisor-related functions in the numeric module.
16namespace divisor
17{
18//! @brief Brief function description.
19//! @return function description (module_function)
20inline static const char* description() noexcept
21{
22 return "NUM_DIVISOR";
23}
24extern const char* version() noexcept;
25
26//! @brief Divisor methods.
27class Divisor
28{
29public:
30 //! @brief Euclidean.
31 //! @param a - first integer
32 //! @param b - second integer
33 //! @return all common divisors of two integers
34 static std::set<std::int32_t> euclidean(const std::int32_t a, const std::int32_t b);
35 //! @brief Stein.
36 //! @param a - first integer
37 //! @param b - second integer
38 //! @return all common divisors of two integers
39 static std::set<std::int32_t> stein(const std::int32_t a, const std::int32_t b);
40
41private:
42 //! @brief Check whether the integer is even.
43 //! @param n - integer to check
44 //! @return be even or not
45 static bool isEven(const std::int32_t n);
46 //! @brief Recursion for the Stein method.
47 //! @param a - first integer
48 //! @param b - second integer
49 //! @return greatest common divisor
50 static std::int32_t steinRecursive(std::int32_t a, std::int32_t b);
51 //! @brief Get all common divisors by the greatest common divisor.
52 //! @param gcd - greatest common divisor
53 //! @return all common divisors
54 static std::set<std::int32_t> getAllDivisors(const std::int32_t gcd);
55};
56} // namespace divisor
57} // namespace numeric
58