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