#pragma once
// a + b sqrt(B)template<typenamemint,longlongB>structAdjunction{usingA=Adjunction;minta,b;Adjunction(mint_a=0,mint_b=0):a(_a),b(_b){}Adjunction(longlongx):a(x),b(0){}friendAoperator+(constA&l,constA&r){return{l.a+r.a,l.b+r.b};}friendAoperator-(constA&l,constA&r){return{l.a-r.a,l.b-r.b};}friendAoperator*(constA&l,constA&r){return{l.a*r.a+l.b*r.b*B,l.a*r.b+l.b*r.a};}friendAoperator/(constA&l,constA&r){returnl*r.inverse();}A&operator+=(constA&r){return(*this)=(*this)+r;}A&operator-=(constA&r){return(*this)=(*this)-r;}A&operator*=(constA&r){return(*this)=(*this)*r;}A&operator/=(constA&r){return(*this)=(*this)/r;}Aoperator-()const{return{-a,-b};}Aoperator+()const{return*this;}Ainverse()const{mintc=(a*a-b*b*B).inverse();return{a*c,-b*c};}Apow(__int128_te)const{Ares{1},c{*this};while(e){if(e&1)res=res*c;c*=c;e>>=1;}returnres;}booloperator==(constA&r)const{returna==r.a&&b==r.b;}booloperator!=(constA&r)const{returna!=r.a||b!=r.b;}friendostream&operator<<(ostream&os,constA&rhs){returnos<<rhs.a<<" "<<rhs.b;}};
#line 2 "modint/adjunction-modint.hpp"
// a + b sqrt(B)template<typenamemint,longlongB>structAdjunction{usingA=Adjunction;minta,b;Adjunction(mint_a=0,mint_b=0):a(_a),b(_b){}Adjunction(longlongx):a(x),b(0){}friendAoperator+(constA&l,constA&r){return{l.a+r.a,l.b+r.b};}friendAoperator-(constA&l,constA&r){return{l.a-r.a,l.b-r.b};}friendAoperator*(constA&l,constA&r){return{l.a*r.a+l.b*r.b*B,l.a*r.b+l.b*r.a};}friendAoperator/(constA&l,constA&r){returnl*r.inverse();}A&operator+=(constA&r){return(*this)=(*this)+r;}A&operator-=(constA&r){return(*this)=(*this)-r;}A&operator*=(constA&r){return(*this)=(*this)*r;}A&operator/=(constA&r){return(*this)=(*this)/r;}Aoperator-()const{return{-a,-b};}Aoperator+()const{return*this;}Ainverse()const{mintc=(a*a-b*b*B).inverse();return{a*c,-b*c};}Apow(__int128_te)const{Ares{1},c{*this};while(e){if(e&1)res=res*c;c*=c;e>>=1;}returnres;}booloperator==(constA&r)const{returna==r.a&&b==r.b;}booloperator!=(constA&r)const{returna!=r.a||b!=r.b;}friendostream&operator<<(ostream&os,constA&rhs){returnos<<rhs.a<<" "<<rhs.b;}};