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