代码拉取完成,页面将自动刷新
<snippet>
<content><![CDATA[
template<int P>
struct MInt {
int x;
MInt(int x = 0) : x(norm(x)) {}
MInt(i64 x) : x(norm(x % P)) {}
explicit operator int() const {
return x;
}
explicit operator i64() const {
return x;
}
int norm(int x) const {
x += (x >= P ? -P : (x < 0 ? P : 0));
return x;
}
// assume -P <= x < 2P
MInt operator-() const {
return MInt(norm(P - x));
}
MInt inv() const {
assert(x != 0);
return power(*this, P - 2);
}
MInt &operator*=(const MInt &rhs) {
x = i64(x) * rhs.x % P;
return *this;
}
MInt &operator+=(const MInt &rhs) {
x = norm(x + rhs.x);
return *this;
}
MInt &operator-=(const MInt &rhs) {
x = norm(x - rhs.x);
return *this;
}
MInt &operator/=(const MInt &rhs) {
return *this *= rhs.inv();
}
friend MInt operator*(const MInt &lhs, const MInt &rhs) {
MInt res = lhs;
res *= rhs;
return res;
}
friend MInt operator+(const MInt &lhs, const MInt &rhs) {
MInt res = lhs;
res += rhs;
return res;
}
friend MInt operator-(const MInt &lhs, const MInt &rhs) {
MInt res = lhs;
res -= rhs;
return res;
}
friend MInt operator/(const MInt &lhs, const MInt &rhs) {
MInt res = lhs;
res /= rhs;
return res;
}
friend std::istream &operator>>(std::istream &is, MInt &a) {
i64 v;
is >> v;
a = MInt(v);
return is;
}
template<class T>
constexpr T power(T a, i64 b) const {
T res = 1;
for (; b; b /= 2, a *= a) {
if (b % 2) {
res *= a;
}
}
return res;
}
friend std::ostream &operator<<(std::ostream &os, const MInt &a) {
return os << a.x;
}
friend bool operator==(const MInt &lhs, const MInt &rhs) {
return lhs.x == rhs.x;
}
friend bool operator!=(const MInt &lhs, const MInt &rhs) {
return lhs.x != rhs.x;
}
friend bool operator<(const MInt &lhs, const MInt &rhs) {
return lhs.x < rhs.x;
}
friend bool operator>(const MInt &lhs, const MInt &rhs) {
return lhs.x > rhs.x;
}
};
using Z = MInt<int(1e9) + 7>;
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- <tabTrigger>hello</tabTrigger> -->
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。