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