typedef unsigned long long ull;
typedef __uint128_t L;
struct FastMod {
ull b, m;
FastMod(ull b) : b(b), m(ull((L(1) << 64) / b)) {}
ull reduce(ull a) {
ull q = (ull)((L(m) * a) >> 64);
ull r = a - q * b; // can be proven that 0 <= r < 2*b
return r >= b ? r - b : r;
}
};
FastMod F(2);
//...
F=FastMod(p);
//快速取模
inline int read(){
ri p=0,z=1;
register char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')z=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
p=p*10+ch-48;
ch=getchar();
}
return p*z;
}
//快读
#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<21],*p1=buf,*p2=buf;
template <typename T>inline void read(T& r) {
r=0;bool w=0; char ch=getchar();
while(ch<'0'||ch>'9') w=ch=='-'?1:0,ch=getchar();
while(ch>='0'&&ch<='9') r=r*10+(ch^48), ch=getchar();
r=w?-r:r;
}
//fread
inline void wt(ri x){
if(x>9)wt(x/10);
putchar(x%10+'0');
}
//write
剪贴板
剪贴板 yf4osmt0
剪贴板信息
剪贴板信息
- 收录
- 更新