22
This commit is contained in:
43
2019/22.cpp
43
2019/22.cpp
@@ -4,9 +4,9 @@
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include <gmpxx.h>
|
||||
|
||||
#include <aocpp/Startup.hpp>
|
||||
#include <zmod.hpp>
|
||||
using namespace zmod;
|
||||
using namespace aocpp;
|
||||
|
||||
template <class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
|
||||
@@ -14,45 +14,6 @@ template <class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
|
||||
|
||||
namespace {
|
||||
|
||||
template <unsigned long Mod>
|
||||
class ZMod {
|
||||
mpz_class value;
|
||||
|
||||
public:
|
||||
ZMod() : value {} {}
|
||||
ZMod(long value) : ZMod{mpz_class{value}} {}
|
||||
ZMod(mpz_class value) {
|
||||
mpz_mod_ui(this->value.get_mpz_t(), value.get_mpz_t(), Mod);
|
||||
}
|
||||
|
||||
auto operator+(ZMod const& rhs) const -> ZMod {
|
||||
return {value + rhs.value};
|
||||
}
|
||||
|
||||
auto operator-() const -> ZMod {
|
||||
return {-value};
|
||||
}
|
||||
|
||||
auto operator-(ZMod const& rhs) const -> ZMod {
|
||||
return {value - rhs.value};
|
||||
}
|
||||
|
||||
auto operator*(ZMod const& rhs) const -> ZMod {
|
||||
return {value * rhs.value};
|
||||
}
|
||||
|
||||
auto inverse() const -> ZMod {
|
||||
mpz_class m{Mod};
|
||||
ZMod result;
|
||||
mpz_invert(result.value.get_mpz_t(), value.get_mpz_t(), m.get_mpz_t());
|
||||
return result;
|
||||
}
|
||||
|
||||
auto friend operator<<(std::ostream & out, ZMod<Mod> const& x) -> std::ostream & {
|
||||
return out << x.value.get_ui();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Rep>
|
||||
struct LinearFunction {
|
||||
Rep scale;
|
||||
|
@@ -50,7 +50,7 @@ add_executable(20 20.cpp)
|
||||
target_link_libraries(20 aocpp)
|
||||
|
||||
add_executable(22 22.cpp)
|
||||
target_link_libraries(22 aocpp PkgConfig::GMP)
|
||||
target_link_libraries(22 aocpp zmod)
|
||||
|
||||
add_executable(23 23.cpp)
|
||||
target_link_libraries(23 aocpp intcode)
|
||||
|
Reference in New Issue
Block a user