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