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