constexpr int P = 998244353;
// guess -P <= X < 2P
int norm(int x) {
if (x < 0) {
x += P;
}
if (x > P) {
x -= P;
}
return x;
}
template <class T>
T power (T a, int b) {
T res = 1;
for (; b; b >>= 1, a *= a) {
if (b & 1) {
res *= a;
}
}
return res;
}
struct Z {
int x;
Z(int x = 0) : x(norm(x)) {}
int val() const {
return x;
}
Z operator - () const {
return Z(norm(P - x));
}
// get inv
Z inv() const {
return power(*this, P - 2);
}
Z &operator *= (const Z &other) {
x = (i64)(x) * other.x % P;
return *this;
}
Z &operator += (const Z &other) {
x = norm(x + other.x);
return *this;
}
Z &operator -= (const Z &other) {
x = norm(x - other.x);
return *this;
}
Z &operator /= (const Z &other) {
return *this *= other.inv();
}
friend Z operator + (const Z &other1, const Z &other2) {
Z res = other1;
res += other2;
return res;
}
friend Z operator - (const Z &other1, const Z &other2) {
Z res = other1;
res -= other2;
return res;
}
friend Z operator * (const Z &other1, const Z &other2) {
Z res = other1;
res *= other2;
return res;
}
friend Z operator / (const Z &other1, const Z &other2) {
Z res = other1;
res /= other2;
return res;
}
};剪贴板
剪贴板 n6d6wxgy
剪贴板信息
剪贴板信息
- 收录
- 更新