模板

快读快写

/*快读*/
template<typename T>
inline void read(T &x){
	x=0; bool flag=0; char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') flag=1;
	for(;isdigit(c);c=getchar()) x=x*10+(c^48);
	if(flag) x=-x;
}

/*快写*/
template<typename F>
inline void write(F x, char ed = '
'){
	static short st[30];short tp=0;
	if(x<0) putchar('-'),x=-x;
	do st[++tp]=x%10,x/=10; while(x);
	while(tp) putchar('0'|st[tp--]);
	putchar(ed);
}

快速幂

int qpow(int a,int b,int p){
	int res=1;
	for(;b;b>>=1,a=(long long)a*a%p) if(b&1) res=(long long)res*a%p;
	return res%p;
}

龟速乘

ll qmul(ll a,ll b,ll p){
	ll res=0;
	for(;b;b>>=1,a=(a+a)%p) if(b&1) res=(res+a)%p;
	return res%p;
}

快速乘

cin>>a>>b>>mod;
cout<<((a*b-(long long)((long double)a*b/mod)*mod+mod)%mod);
原文地址:https://www.cnblogs.com/DReamLion/p/14457439.html