#include #include #include #include using namespace std; using mint=atcoder::modint998244353; #include template struct Matrix{ array,N>dat; array&operator[](int i){return dat[i];} const array&operator[](int i)const{return dat[i];} static Matrix eye(){ Matrix res; for(int i=0;i>=1)if(n&1)res=res*a; return res; } }; using mat=Matrix; int A,B,P,Q; main() { cin>>A>>B>>P>>Q; int sqP=2e5; mat X; X[0][0]=A;X[0][1]=-B;X[1][0]=1;X[1][1]=0; mat E=X.pow(sqP); vector,int> >tb(sqP); paire=make_pair(P,Q); for(int i=0;ifirst==e) { long N=s+it->second+2; cout<