#include "num.h"
#include <iostream>
Num::Num(int value, int modulo) {
if (modulo != 0) this->value = value % modulo;
else this->value = value;
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) {
Num obj((this->value + other.value) % this->modulo, this->modulo);
return obj;
}
Num Num::operator-(const Num &other) {
Num obj((this->value - other.value) % this->modulo, this->modulo);
return obj;
}
Num Num::operator*(const Num &other) {
Num obj((this->value * other.value) % this->modulo, this->modulo);
return obj;
}
Num Num::operator+(int num) {
this->value += num;
this->value %= this->modulo;
return *this;
}
Num Num::operator-(int num) {
this->value -= num;
this->value %= this->modulo;
return *this;
}
Num Num::operator*(int num) {
this->value *= num;
this->value %= this->modulo;
return *this;
}
Num &Num::operator+=(const Num &other) {
this->modulo = modulo;
this->value += other.value;
this->value %= this->modulo;
return *this;
}
Num &Num::operator-=(const Num &other) {
this->modulo = modulo;
this->value -= other.value;
this->value %= this->modulo;
if (this->value < 0) {
this->value = this->modulo + this->value;
}
return *this;
}
Num &Num::operator*=(const Num &other) {
this->value = ((int64_t) this->value * other.value) % modulo;
this->modulo = modulo;
this->value %= this->modulo;
return *this;
}
Num &Num::operator+=(int num) {
this->value = ((int64_t) this->value + num) % this->modulo;
return *this;
}
Num &Num::operator-=(int num) {
this->value -= num;
this->value %= this->modulo;
if (this->value < 0)
this->value = this->modulo + this->value;
return *this;
}
Num &Num::operator*=(int num) {
this->value = ((int64_t) this->value * num) % this->modulo;
return *this;
}