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