跳到正文

剪贴板

剪贴板 j1a7guj9

原文
剪贴板信息

剪贴板信息

收录
更新
C++
const int p=1e9+7;
template<class _Tp,class _tp>void add(_Tp&x,const _tp& y){((x+=y)>=p)&&(x-=p);}template<class _Tp,class _tp>_Tp Add(_Tp x,const _tp y){add(x,y);return x;}
template<class _Tp,class _tp>void sub(_Tp&x,const _tp&y){((x-=y)<0)&&(x+=p);}template<class _Tp,class _tp>_Tp Sub(_Tp x,const _tp y){sub(x,y);return x;}
template<class _Tp,class _tp>void mul(_Tp&x,const _tp&y){x=1ll*x*y%p;}template<class _Tp,class _tp>_Tp Mul(const _Tp x,const _tp y){return 1ll*x*y%p;}
template<class _Tp,class _tp>_Tp ksm(_Tp a,_tp b){_Tp ans(1);for(;b;b>>=1,mul(a,a))if(b&1)mul(ans,a);return ans;}
template<class _Tp>_Tp div2(_Tp a){if(a&1)a+=p;return a>>1;}
struct gsm{
	#define _Tp long long
	int _[32768][2],mx;
	gsm(int o,_Tp lim){
		mx=sqrt(lim)+1;
		_[0][0]=_[0][1]=1;
		for(int i=1;i<=mx;i++)_[i][0]=Mul(_[i-1][0],o);
		for(int i=1;i<=mx;i++)_[i][1]=Mul(_[i-1][1],_[mx][0]);
	}
	int operator()(_Tp x){return Mul(_[x%mx][0],_[x/mx][1]);}
};

自带预处理,用法方便

C++
gsm A(2,1919810);//最大询问到1919810
cout<<A(114514);//询问2^114514

struct\text{struct} 里面一开始开了一个 65536×265536\times2 的数组,然后爆了,真是太逊了。