#include using namespace std; #define all(a) a.begin(),a.end() #define pb push_back #define sz(a) ((int)a.size()) using ll=long long; using u32=unsigned int; using u64=unsigned long long; using i128=__int128; using u128=unsigned __int128; using f128=__float128; using pii=pair; using pll=pair; template using vc=vector; template using vvc=vc>; template using vvvc=vc>; using vi=vc; using vll=vc; using vvi=vc; using vvll=vc; #define vv(type,name,n,...) \ vector> name(n,vector(__VA_ARGS__)) #define vvv(type,name,n,m,...) \ vector>> name(n,vector>(m,vector(__VA_ARGS__))) template using min_heap=priority_queue,greater>; template using max_heap=priority_queue; // https://trap.jp/post/1224/ #define rep1(n) for(ll i=0; i<(ll)(n); ++i) #define rep2(i,n) for(ll i=0; i<(ll)(n); ++i) #define rep3(i,a,b) for(ll i=(ll)(a); i<(ll)(b); ++i) #define rep4(i,a,b,c) for(ll i=(ll)(a); i<(ll)(b); i+=(c)) #define cut4(a,b,c,d,e,...) e #define rep(...) cut4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__) #define per1(n) for(ll i=((ll)n)-1; i>=0; --i) #define per2(i,n) for(ll i=((ll)n)-1; i>=0; --i) #define per3(i,a,b) for(ll i=((ll)a)-1; i>=(ll)(b); --i) #define per4(i,a,b,c) for(ll i=((ll)a)-1; i>=(ll)(b); i-=(c)) #define per(...) cut4(__VA_ARGS__,per4,per3,per2,per1)(__VA_ARGS__) #define rep_subset(i,s) for(ll i=(s); i>=0; i=(i==0?-1:(i-1)&(s))) template constexpr T ifloor(const T a, const S b){return a/b-(a%b&&(a^b)<0);} template constexpr T iceil(const T a, const S b){return ifloor(a+b-1,b);} template void sort_unique(vector &vec){ sort(vec.begin(),vec.end()); vec.resize(unique(vec.begin(),vec.end())-vec.begin()); } template constexpr bool chmin(T &a, const S b){if(a>b) return a=b,true; return false;} template constexpr bool chmax(T &a, const S b){if(a istream& operator >> (istream& i, pair &p){return i >> p.first >> p.second;} template ostream& operator << (ostream& o, const pair &p){return o << p.first << ' ' << p.second;} #ifdef i_am_noob #define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__) template void _do(vector x){for(auto i: x) cerr << i << ' ';cerr << "\n";} template void _do(set x){for(auto i: x) cerr << i << ' ';cerr << "\n";} template void _do(unordered_set x){for(auto i: x) cerr << i << ' ';cerr << "\n";} template void _do(T && x) {cerr << x << endl;} template void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);} #else #define bug(...) 777771449 #endif template void print(vector x){for(auto i: x) cout << i << ' ';cout << "\n";} template void print(set x){for(auto i: x) cout << i << ' ';cout << "\n";} template void print(unordered_set x){for(auto i: x) cout << i << ' ';cout << "\n";} template void print(T && x) {cout << x << "\n";} template void print(T && x, S&&... y) {cout << x << ' ';print(y...);} template istream& operator >> (istream& i, vector &vec){for(auto &x: vec) i >> x; return i;} vvi read_graph(int n, int m, int base=1){ vvi adj(n); for(int i=0,u,v; i> u >> v,u-=base,v-=base; adj[u].pb(v),adj[v].pb(u); } return adj; } vvi read_tree(int n, int base=1){return read_graph(n,n-1,base);} template pair operator + (const pair &a, const pair &b){return {a.first+b.first,a.second+b.second};} template constexpr T inf=0; template<> constexpr int inf = 0x3f3f3f3f; template<> constexpr ll inf = 0x3f3f3f3f3f3f3f3f; template vector operator += (vector &a, int val){for(auto &i: a) i+=val; return a;} template T isqrt(const T &x){T y=sqrt(x+2); while(y*y>x) y--; return y;} #define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #include using namespace atcoder; using mint=modint998244353; //using mint=modint1000000007; ll mul(ll x, ll y, ll p) {return (x * y - (ll)((long double)x / p * y) * p + p) % p;} vector chk = {2, 325, 9375, 28178, 450775, 9780504, 1795265022}; ll Pow(ll a, ll b, ll n) { ll res = 1; for (; b; b >>= 1, a = mul(a, a, n)) if (b & 1) res = mul(res, a, n); return res; } bool check(ll a, ll d, int s, ll n) { a = Pow(a, d, n); if (a <= 1) return 1; for (int i = 0; i < s; ++i, a = mul(a, a, n)) { if (a == 1) return 0; if (a == n - 1) return 1; } return 0; } bool IsPrime(ll n) { if (n < 2) return 0; if (n % 2 == 0) return n == 2; ll d = n - 1, s = 0; while (d % 2 == 0) d >>= 1, ++s; for (ll i : chk) if (!check(i, d, s, n)) return 0; return 1; } const vector small = {2, 3, 5, 7, 11, 13, 17, 19}; ll FindFactor(ll n) { if (IsPrime(n)) return 1; for (ll p : small) if (n % p == 0) return p; ll x, y = 2, d, t = 1; auto f = [&](ll a) {return (mul(a, a, n) + t) % n;}; for (int l = 2; ; l <<= 1) { x = y; int m = min(l, 32); for (int i = 0; i < l; i += m) { d = 1; for (int j = 0; j < m; ++j) { y = f(y), d = mul(d, abs(x - y), n); } ll g = __gcd(d, n); if (g == n) { l = 1, y = 2, ++t; break; } if (g != 1) return g; } } } map res; void PollardRho(ll n) { if (n == 1) return; if (IsPrime(n)) return ++res[n], void(0); ll d = FindFactor(n); PollardRho(n / d), PollardRho(d); } void ahcorz(){ int t; ll m; cin >> t >> m; res.clear(); PollardRho(m); vc> pr; for(auto &[p,x]: res) pr.pb({p,x}); vc> vec; rep(1<>j&1) cur*=pr[j].first; cur=m/cur; vec.pb({cur,__builtin_parity(i)?-1:1}); } while(t--){ int n,_B,_C,_D; cin >> n >> _B >> _C >> _D; mint B=_B,C=_C,D=_D; vc w(n); w[0]=B; rep(i,n-1) w[i+1]=w[i]*C+D; mint res; vc tot(1<> x; ll y=x; bool ok=1; int val=1; rep(j,sz(pr)){ int cnt=0; while(x%pr[j].first==0) x/=pr[j].first,cnt++; if(cnt>pr[j].second){ ok=0; break; } if(cnt==pr[j].second); else if(cnt==pr[j].second-1) val*=-1; else val=0; } if(x>1) ok=0; if(!ok) continue; rep(j,1<> t; while(t--) ahcorz(); }