#include "num.h"
#include <iostream>
Num::Num(int Value, int Modulo) {
value = (Modulo != 0) ? Value % Modulo : Value;
modulo = Modulo;
}
Num &Num::operator = (const Num &other) {
value = other.value;
return *this;
}
Num Num::operator + (const Num &other) {
return Num(value + other.value, modulo);
}
Num Num::operator - (const Num &other) {
return Num(value - other.value, modulo);
}
Num Num::operator * (const Num &other) {
int64_t val = (static_cast<int64_t> (value) *
other.value) % modulo;
return Num( static_cast<int>(val), modulo);
}
Num Num::operator + (int num) {
num %= modulo;
return Num(value + num, modulo);
}
Num Num::operator - (int num) {
num %= modulo;
return Num(value - num, modulo);
}
Num Num::operator * (int num) {
num %= modulo;
return Num(value * num, modulo);
}
Num &Num::operator+=(const Num &other) {
value += other.value;
return *this;
}
Num &Num::operator-=(const Num &other) {
value -= other.value;
while (value < 0) {
value += modulo;
}
value %= modulo;
return *this;
}
Num &Num::operator*=(const Num &other) {
value *= other.value;
return *this;
}
Num &Num::operator += (int num) {
num %= modulo;
value %= modulo;
value = (value + num) % modulo;
return *this;
}
Num &Num::operator -= (int num) {
value -= num;
while (value < 0) {
value += modulo;
}
value %= modulo;
return *this;
}
Num &Num::operator *= (int num) {
value = (static_cast<int64_t> (value)
* num) % modulo;
return *this;
}