11#ifndef _TPF_EUCLIDEAN_HPP
12#define _TPF_EUCLIDEAN_HPP
19 #if _MSVC_LANG < 201703L
20 #error This libary requires C++17 Standard (Visual Studio 2017).
24 #if __cplusplus < 201703
25 #error This library requires C++17 Standard (GNU g++ version 8.0 or clang++ version 8.0 above)
45 using namespace types;
48 template<
typename Type>
61 template<
template<
typename,
typename...>
class ContainerType,
typename EleType>
62 enable_if_in_list_t<EleType, integral_list_t>
63 gcd(
const ContainerType<EleType>& container)
69 size_t size = container.size();
72 return container.front();
74 return gcd(container[0], container[1]);
77 auto g =
gcd(container[0], container[1]);
78 for(
size_t i=2; i < size; ++i)
79 g =
gcd(g, container[i]);
86 template<
typename Type,
typename... Types>
87 auto gcd(Type arg, Types... args)
89 return gcd(arg,
gcd(args...));
93 template<
typename Type>
94 enable_if_in_list_t<Type, integral_list_t>
97 return (a /
gcd(a, b)) * b;
100 template<
typename Type,
typename... Types>
101 auto lcm(Type arg, Types... args)
103 return lcm(arg,
lcm(args...));
106 template<
template<
typename,
typename...>
class ContainerType,
typename EleType>
107 enable_if_in_list_t<EleType, integral_list_t>
108 lcm(
const ContainerType<EleType>& container)
110 if(container.empty())
114 size_t size = container.size();
117 return container.front();
119 return lcm(container[0], container[1]);
122 auto l =
lcm(container[0], container[1]);
124 for(
size_t i=2; i < size; ++i)
125 l =
lcm(l, container[i]);
132 template<
typename Type>
133 enable_if_in_list_t<Type, integral_list_t, void>
152 template<
typename Type>
155 std::vector<Type> q; q.reserve(100);
161 q.emplace_back(-(a / b));
173 x = 0; y = 1;
return b;
178 size_t cache_count = q.size();
180 for (
size_t i = cache_count - 2; i != 0; --i)
182 Type tmp = x; x = y; y = tmp + y*q[i];
187 Type tmp = x; x = y; y = tmp + y*q[0];
198 template<
typename Type>
204 if (b1 > a1) std::swap(a1, b1);
212 if (a * x + b * y != g)
Type extended_euclidean_algorithm(Type a, Type b, Type &x, Type &y)
enable_if_in_list_t< Type, integral_list_t, void > reduce(Type &a, Type &b)
Type extended_euclidean_algorithm(Type a, Type b, Type &x, Type &y)
enable_if_in_list_t< Type, integral_list_t > lcm(Type a, Type b)
enable_if_in_list_t< Type, integral_list_t > gcd(Type a, Type b)
Type to string name conversions are defined.
hidden::enable_if_in_list_t< TestType, TypeList, ReturnType > enable_if_in_list_t
Includes subnamespace conversion.
Type functions are implemented.