#include "num.h"
#include <cmath>

Num::Num(int value_, int modulo_) {
    value = value_ % modulo_;
    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) {
    return Num(value * other.value, modulo);
}
Num Num::operator+(int num) {
    value += num;
    value %= modulo;
    return Num(value, modulo);
}
Num Num::operator-(int num) {
    value -= num;
    value %= modulo;
    return Num(value, modulo);
}
Num Num::operator*(int num) {
    value *= num;
    value %= modulo;
    return Num(value, modulo);
}
Num& Num::operator+=(const Num& other) {
    value += other.value;
    value %= modulo;
    return  *this;
}
Num& Num::operator-=(const Num& other) {
    value -= other.value;
    if (value < 0) value = value - floor(static_cast<double>value / modulo) * modulo;
    else
        value %= modulo;
    return *this;
}
Num& Num::operator*=(const Num& other) {
    value *= other.value;
    value %= modulo;
    return *this;
}
Num& Num::operator+=(int num) {
    int64_t qwerty = static_cast<int64_t>value;
    qwerty += num;
    qwerty %= modulo;
    value = qwerty;
    return *this;
}
Num& Num::operator-=(int num) {
    value -= num;
    if (value < 0) value = value - floor(static_cast<double>value / modulo) * modulo;
    else
        value %= modulo;
    return *this;
}
Num& Num::operator*=(int num) {
    int64_t qwerty = static_cast<int64_t>value;
    qwerty *= num;
    qwerty %= modulo;
    value = qwerty;
    return *this;
}