#include "num.h" #include #include 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 = value; answer = (answer * num) % static_cast(modulo); return {static_cast(answer), this->modulo}; } Num &Num::operator*=(int num) { int64_t answer = value; answer = (answer * num) % static_cast(modulo); this->value = static_cast(answer); return *this; } Num Num::operator+(int num) { int64_t answer = static_cast(value) + static_cast(num); if (modulo != 0) answer %= static_cast(modulo); return {static_cast(answer), this->modulo}; } Num &Num::operator+=(int num) { int64_t answer = static_cast(value) + static_cast(num); if (modulo != 0) answer %= static_cast(modulo); this->value = static_cast(answer); return *this; } Num Num::operator-(int num) { int64_t answer = static_cast(value) - static_cast(num); if (modulo != 0) { answer %= static_cast(modulo); } return {static_cast(answer), this->modulo}; } Num &Num::operator-=(int num) { int64_t answer = static_cast(value) - static_cast(num); if (answer < 0) { answer += (answer / static_cast(modulo) + 1) * static_cast(modulo); } if (modulo != 0) { answer %= static_cast(modulo); } this->value = static_cast(answer); 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; }