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