# 【BZOJ2242】[SDOI2011] 计算器（数学模板三合一）

### 代码

#include<bits/stdc++.h>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define uint unsigned int
#define LL long long
#define ull unsigned long long
#define swap(x,y) (x^=y,y^=x,x^=y)
#define abs(x) ((x)<0?-(x):(x))
#define INF 1e9
#define Inc(x,y) ((x+=(y))>=MOD&&(x-=MOD))
#define ten(x) (((x)<<3)+((x)<<1))
using namespace std;
int Q;
class FIO
{
private:
#define Fsize 100000
#define pc(ch) (FoutSize<Fsize?Fout[FoutSize++]=ch:(fwrite(Fout,1,FoutSize,stdout),Fout[(FoutSize=0)++]=ch))
int f,FoutSize,OutputTop;char ch,Fin[Fsize],*FinNow,*FinEnd,Fout[Fsize],OutputStack[Fsize];
public:
FIO() {FinNow=FinEnd=Fin;}
inline void read(int &x) {x=0,f=1;while(!isdigit(ch=tc())) f=ch^'-'?1:-1;while(x=ten(x)+(ch&15),isdigit(ch=tc()));x*=f;}
inline void read_string(string &x) {x="";while(isspace(ch=tc()));while(x+=ch,!isspace(ch=tc())) if(!~ch) return;}
inline void write(int x) {if(!x) return (void)pc('0');if(x<0) pc('-'),x=-x;while(x) OutputStack[++OutputTop]=x%10+48,x/=10;while(OutputTop) pc(OutputStack[OutputTop]),--OutputTop;}
inline void write_char(char x) {pc(x);}
inline void write_string(string x) {register int i,len=x.length();for(i=0;i<len;++i) pc(x[i]);}
inline void end() {fwrite(Fout,1,FoutSize,stdout);}
}F;
class Class_QuickPowSolver//用快速幂处理第一个任务
{
private:
inline int quick_pow(int x,int y,int MOD,register int res=1)//快速幂板子
{
for(;y;x=1LL*x*x%MOD,y>>=1) if(y&1) res=1LL*res*x%MOD;
return res;
}
public:
inline void Solve()
{
register int x,y,p;
}
}QuickPowSolver;
class Class_ExgcdSolver//用exgcd处理第二个任务
{
private:
inline int exgcd(int x,int y,int &s1,int &s2)//扩欧板子
{
if(!y) return s1=1,s2=0,x;
register int res=exgcd(y,x%y,s2,s1);
return s2-=x/y*s1,res;
}
inline int GetAns(int x,int y,int MOD)//求解同余方程
{
register int s1,s2,g=exgcd(x,MOD,s1,s2);
if(y%g) return -1;//无解
return MOD/=g,((1LL*s1*(y/g)%MOD)+MOD)%MOD;//返回答案
}
public:
inline void Solve()
{
register int x,y,p,res;
while(Q--)
{
else F.write_string("Orz, I cannot find x!\n");
}
}
}ExgcdSolver;
class Class_BsgsSolver//用BSGS处理第三个任务
{
private:
map<int,int> s,new_map;
inline int BSGS(int x,int y,int MOD)//BSGS板子
{
register int i,t=1,base,Size=ceil(sqrt(MOD));
for(i=0,s=new_map;i<=Size;++i) s[1LL*t*y%MOD]=i,base=t,t=1LL*t*x%MOD;
for(t=base,i=1;i<=Size;++i,t=1LL*t*base%MOD) if(s[t]) return 1LL*i*Size-s[t];
return 0;//无解返回0
}
public:
inline void Solve()
{
register int x,y,p,res;
while(Q--)
{
else F.write_string("Orz, I cannot find x!\n");
}
}
}BsgsSolver;
int main()
{
register int op;