// // Created by Дени Абакаев on 21.11.2021. // #include "num.h" Num::Num(int value, int modulo) { if (modulo == 0) { this->value = value; this->modulo = 0; } else { this->value = value % modulo; this->modulo = modulo; } } Num &Num::operator=(const Num &other) = default; 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) { return Num((this->value * other.value), this->modulo); } Num Num::operator+(int num) { return Num((this->value + num), this->modulo); } Num Num::operator-(int num) { return Num((this->value - num), this->modulo); } Num Num::operator*(int num) { return Num((this->value * num), this->modulo); } Num &Num::operator+=(const Num &other) { this->value = (this->value + other.value) % this->modulo; return *this; } Num &Num::operator-=(const Num &other) { this->value = (this->value - other.value) % this->modulo; if (this->value < 0) { this->value = this->modulo + this->value } return *this; } Num &Num::operator*=(const Num &other) { this->value = (this->value * other.value) % this->modulo; return *this; } Num &Num::operator*=(int num) { this->value = (this->value + num) % this->modulo; return *this; } Num &Num::operator+=(int num) { this->value = (this->value + num) % this->modulo; return *this; } Num &Num::operator-=(int num) { this->value = (this->value - num) % this->modulo; if (this->value < 0) { this->value = this->modulo + this->value } return *this; }