aboutsummaryrefslogtreecommitdiff
path: root/zmodn.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-01-14 21:32:09 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2025-01-14 21:32:09 +0100
commit38efc7d2df030d37e3f20efbce71fadad1294cef (patch)
treebbe8a7bbb6acbeb2b7ed54c189d1e719a7459427 /zmodn.h
parent8ca27427af98bd3a82e8c5f4a199513295747930 (diff)
downloadzmodn-38efc7d2df030d37e3f20efbce71fadad1294cef.tar.gz
zmodn-38efc7d2df030d37e3f20efbce71fadad1294cef.zip
Added BigInt
Diffstat (limited to 'zmodn.h')
-rw-r--r--zmodn.h25
1 files changed, 20 insertions, 5 deletions
diff --git a/zmodn.h b/zmodn.h
index fdb1ee6..a24f293 100644
--- a/zmodn.h
+++ b/zmodn.h
@@ -7,16 +7,31 @@
7#include <tuple> 7#include <tuple>
8#include <type_traits> 8#include <type_traits>
9 9
10template<typename INT> 10template<typename T>
11requires std::is_integral_v<INT> 11concept Integer = requires(T a, T b, int i, std::ostream& os) {
12std::tuple<INT, INT, INT> extended_gcd(INT a, INT b) { 12 {T(i)};
13
14 {a + b} -> std::same_as<T>;
15 {a - b} -> std::same_as<T>;
16 {a * b} -> std::same_as<T>;
17 {a / b} -> std::same_as<T>;
18 {a % b} -> std::same_as<T>;
19
20 {a == b} -> std::same_as<bool>;
21 {a != b} -> std::same_as<bool>;
22
23 {os << a} -> std::same_as<std::ostream&>;
24};
25
26template<Integer T>
27std::tuple<T, T, T> extended_gcd(T a, T b) {
13 if (b == 0) return {a, 1, 0}; 28 if (b == 0) return {a, 1, 0};
14 auto [g, x, y] = extended_gcd(b, a%b); 29 auto [g, x, y] = extended_gcd(b, a%b);
15 return {g, y, x - y*(a/b)}; 30 return {g, y, x - y*(a/b)};
16} 31}
17 32
18template<auto N> 33template<Integer auto N>
19requires(N > 1) && std::is_integral_v<decltype(N)> 34requires(N > 1)
20class Zmod { 35class Zmod {
21public: 36public:
22 Zmod(decltype(N) z) : value{(z%N + N) % N} {} 37 Zmod(decltype(N) z) : value{(z%N + N) % N} {}