#include #include "num.h" Num::Num(int val, int mod): value(mod ? val % mod : val), modulo(mod) {} Num& Num::operator=(const Num& other) { value = other.value; return *this; } Num Num::operator+(const Num& other) { return Num((value + other.value) % modulo, modulo); } Num Num::operator-(const Num& other) { int min = value - other.value; return Num((min >= 0 ? min : modulo + min), modulo); } Num Num::operator*(const Num& other) { return Num((value * other.value), modulo); } Num Num::operator+(int num) { return Num((value + num), modulo); } Num Num::operator-(int num) { int min = value - num; return Num((min >= 0 ? min : modulo + min), modulo); } Num Num::operator*(int num) { return Num((value * num), modulo); } Num& Num::operator+=(const Num& other) { value = (value + other.value) % modulo; return *this; } Num& Num::operator-=(const Num& other) { int min = value - other.value; value = min >= 0 ? min : modulo + min; return *this; } Num& Num::operator*=(const Num& other) { value = (value * other.value) % modulo; return *this; } Num& Num::operator+=(int num) { long long int VAL = value; value = (VAL + num) % modulo; return *this; } Num& Num::operator-=(int num) { int min = value - num; value = min >= 0 ? min : modulo + min; return *this; } Num& Num::operator*=(int num) { value = (long long int(value) * num) % modulo; return *this; }