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