diff --git a/number/mll.cc b/number/mll.cc new file mode 100644 index 0000000..c0adf58 --- /dev/null +++ b/number/mll.cc @@ -0,0 +1,19 @@ +template struct MLL { + ll val; + MLL(ll v = 0) : val(mod(v, mdl)) {} + MLL operator+(const MLL& rhs) { return mod(val + rhs.val, mdl); } + MLL operator-(const MLL& rhs) { return mod(val - rhs.val, mdl); } + MLL operator*(const MLL& rhs) { return mod(val * rhs.val, mdl); } + MLL operator/(const MLL& rhs) { return mod(val * mod(inverse(rhs.val, mdl), mdl), mdl); } + MLL operator%(const MLL& rhs) { return mod(val - (*this / rhs).val, mdl); } + 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; } +}; + +template +ostream& operator<<(ostream& out, const MLL& num) { + return out << num.val; +}