2024-03-23 15:32:27 +00:00
|
|
|
template <ll mdl> struct MLL {
|
|
|
|
ll val;
|
|
|
|
MLL(ll v = 0) : val(mod(v, mdl)) {}
|
2024-04-01 15:48:45 +01:00
|
|
|
friend MLL operator+(const MLL& lhs, const MLL& rhs) { return mod(lhs.val + rhs.val, mdl); }
|
|
|
|
friend MLL operator-(const MLL& lhs, const MLL& rhs) { return mod(lhs.val - rhs.val, mdl); }
|
|
|
|
friend MLL operator*(const MLL& lhs, const MLL& rhs) { return mod(lhs.val * rhs.val, mdl); }
|
|
|
|
friend MLL operator/(const MLL& lhs, const MLL& rhs) { return mod(lhs.val * mod(inverse(rhs.val, mdl), mdl), mdl); }
|
|
|
|
friend MLL operator%(const MLL& lhs, const MLL& rhs) { return mod(lhs.val - (lhs / rhs).val, mdl); }
|
2024-04-10 05:50:26 +01:00
|
|
|
friend bool operator==(const MLL& lhs, const MLL& rhs) { return lhs.val == rhs.val; }
|
|
|
|
friend bool operator!=(const MLL& lhs, const MLL& rhs) { return lhs.val != rhs.val; }
|
2024-03-23 15:32:27 +00:00
|
|
|
void operator+=(const MLL& rhs) { val = (*this + rhs).val; }
|
|
|
|
void operator-=(const MLL& rhs) { val = (*this - rhs).val; }
|
|
|
|
void operator*=(const MLL& rhs) { val = (*this * rhs).val; }
|
|
|
|
void operator/=(const MLL& rhs) { val = (*this / rhs).val; }
|
|
|
|
void operator%=(const MLL& rhs) { val = (*this % rhs).val; }
|
|
|
|
};
|
2024-04-10 05:25:35 +01:00
|
|
|
|
|
|
|
template <ll mdl>
|
|
|
|
ostream& operator<<(ostream& out, const MLL<mdl>& num) {
|
|
|
|
return out << num.val;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <ll mdl>
|
|
|
|
istream& operator>>(istream& in, MLL<mdl>& num) {
|
|
|
|
return in >> num.val;
|
2024-04-10 05:50:26 +01:00
|
|
|
}
|