卡特兰数相关:
容斥相关,见反演。
求组合数:预处理逆元。上限在
预处理, 递归求组合数 : Lucas 定理。
快读 与 快写
#pragma GCC target("avx")
namespace FastIO {
char buf[1 << 9], buf2[1 << 21], a[20], *p1 = buf, *p2 = buf, hh = '\n';
long long p, p3 = -1;
void read() {}
void print() {}
inline int getc() {
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 9, stdin), p1 == p2) ? EOF : *p1++;
}
inline void flush() {
fwrite(buf2, 1, p3 + 1, stdout), p3 = -1;
}
template <typename T, typename... T2>
inline void read(T &x, T2 &...oth) {
long long f = 0;
x = 0;
char ch = getc();
while (!isdigit(ch)) {
if (ch == '-') f = 1;
ch = getc();
}
while (isdigit(ch)) {
x = (x << 1) + (x << 3) + (ch ^ '0');
ch = getc();
}
x = f ? -x : x;
read(oth...);
}
template <typename T, typename... T2>
inline void print(T x, T2... oth) {
if (p3 > 1 << 20)
flush();
if (x < 0)
buf2[++p3] = 45, x = -x;
do {
a[++p] = x % 10 + 48;
} while (x /= 10);
do {
buf2[++p3] = a[p];
} while (--p);
buf2[++p3] = hh;
print(oth...);
}
}
#define read FastIO::read
#define print FastIO::print
//使用时用print(x) 将x存入缓冲区
//最后用 FastIO :: flush();输出缓冲区中数
或 -----------------------
//适用于 int
namespace FastIO{
char buf[1 << 9], *p1 = buf, *p2 = buf;
void read(){}
inline int getc(){
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 9, stdin), p1 == p2) ? EOF : *p1 ++;
}
template <typename T>
inline void read(T &x){
x = 0;
char ch = getc();
while(!isdigit(ch)) ch = getc();
while(isdigit(ch)){
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getc();
}
}
}
#define read FastIO::read
快速乘
inline ll Mul(ll x,ll y,ll p)
{
if(y < 0) x = - x, y = - y;
ll z = (long double)x / p * y;
ll res = (unsigned long long)x * y - (unsigned long long)z * p;
return (res + p) % p;
}模法
typedef long long ll;
typedef __int128 i128;
i128 InvMod = ((i128(1) << 64) / Mod) + 1;
inline int mod(ll x){
return x - ll(x * InvMod >> 64) * Mod;
}