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