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