1 Star 2 Fork 0

rlmnsk/算法与数据结构

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
mint.sublime-snippet 2.55 KB
一键复制 编辑 原始数据 按行查看 历史
rlmnsk 提交于 2023-02-27 13:11 . update mint.sublime-snippet.
<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>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/rlmnsk/algorithm-and-data-structure.git
git@gitee.com:rlmnsk/algorithm-and-data-structure.git
rlmnsk
algorithm-and-data-structure
算法与数据结构
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385