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

inline Num::Num(int value, int modulo) : value(value), modulo(modulo) {
    if (modulo != 0) {
        this->value = value % modulo;
    }
}

inline Num& Num::operator=(const Num& other) {
    return *this;
}

inline Num Num::operator+(const Num& other) {
    return Num(this->value + other.value, modulo);
}

inline Num Num::operator-(const Num& other) {
    return Num(this->value - other.value, modulo);
}

inline Num Num::operator*(const Num& other) {
    return Num(this->value * other.value, modulo);
}

inline Num Num::operator+(int num) {
    this->value = value + num;
    return *this;
}

inline Num Num::operator-(int num) {
    this->value = value - num;
    return *this;
}

inline Num Num::operator*(int num) {
    this->value = value * num;
    return *this;
}

inline Num& Num::operator+=(const Num& other) {
    this->value = (value + other.value) % modulo;
    return *this;
}

inline Num& Num::operator-=(const Num& other) {
    if (value - other.value < 0) {
        this->value = value - other.value + modulo;
    }
    else {
        this->value = value - other.value;
    }
    return *this;
}

inline Num& Num::operator*=(const Num& other) {
    this->value = (value * other.value) % modulo;
    return *this;
}

inline Num& Num::operator+=(int num) {
    this->value = (value + num % modulo) % modulo;
    return *this;
}

inline Num& Num::operator-=(int num) {
    if (value - num % modulo < 0) {
        this->value = value - num % modulo + modulo;
    }
    else {
        this->value = value - num % modulo;
    }
    return *this;
}

inline Num& Num::operator*=(int num) {
    int64_t a, b;
    a = static_cast<uint64_t>(value);
    b = static_cast<uint64_t>(num);
    this->value = (a * b % modulo) % modulo;
    return *this;
}