#include "num.h" #include Num::Num(int value, int modulo) { this->value = value % modulo; this->modulo = modulo; if (this->value < 0) { this->value += this->modulo; } } Num &Num::operator=(const Num &other) { this->value = other.value; return *this; } Num &Num::operator+=(const Num &other) { int64_t val = static_cast(this->value) + static_cast(other.value); val %= this->modulo; this->value = static_cast(val); if (this->value < 0) { this->value += this->modulo; } return *this; } Num &Num::operator-=(const Num &other) { int64_t val = static_cast(this->value) - static_cast(other.value); val %= this->modulo; this->value = static_cast(val); if (this->value < 0) { this->value += this->modulo; } return *this; } Num &Num::operator*=(const Num &other) { int64_t val = static_cast(this->value) * static_cast(other.value); val %= this->modulo; this->value = static_cast(val); if (this->value < 0) { this->value += this->modulo; } return *this; } Num &Num::operator+=(int num) { int64_t val = static_cast(this->value) + static_cast(num); val %= this->modulo; this->value = static_cast(val); if (this->value < 0) { this->value += this->modulo; } return *this; } Num &Num::operator-=(int num) { int64_t val = static_cast(this->value) - static_cast(num); val %= this->modulo; this->value = static_cast(val); if (this->value < 0) { this->value += this->modulo; } return *this; } Num &Num::operator*=(int num) { int64_t val = static_cast(this->value) * static_cast(num); val %= this->modulo; this->value = static_cast(val); if (this->value < 0) { this->value += this->modulo; } return *this; } Num Num::operator+(const Num &other) { int64_t val = static_cast(this->value) + static_cast(other.value); val %= this->modulo; if (val < 0) { val += this->modulo; } return Num(static_cast(val), this->modulo); } Num Num::operator-(const Num &other) { int64_t val = static_cast(this->value) - static_cast(other.value); val %= this->modulo; if (val < 0) { val += this->modulo; } return Num(static_cast(val), this->modulo); } Num Num::operator*(const Num &other) { int64_t val = static_cast(this->value) * static_cast(other.value); val %= this->modulo; if (val < 0) { val += this->modulo; } return Num(static_cast(val), this->modulo); } Num Num::operator+(int num) { int64_t val = static_cast(this->value) + static_cast(num); val %= this->modulo; if (val < 0) { val += this->modulo; } return Num(static_cast(val), this->modulo); } Num Num::operator-(int num) { int64_t val = static_cast(this->value) - static_cast(num); val %= this->modulo; if (val < 0) { val += this->modulo; } return Num(static_cast(val), this->modulo); } Num Num::operator*(int num) { int64_t val = static_cast(this->value) * static_cast(num); val %= this->modulo; if (val < 0) { val += this->modulo; } return Num(static_cast(val), this->modulo); }