#include using namespace std; using ll = long long; const ll modc = 998244353; ll mod_exp(ll b, ll e, ll m){ if (e > 0 && b == 0) return 0; ll ans = 1; b %= m; while (e > 0){ if ((e & 1LL)) ans = (ans * b) % m; e = e >> 1LL; b = (b*b) % m; } return ans; } class mint { ll x; public: mint(ll x=0) : x((x%modc+modc)%modc) {} mint operator-() const { return mint(-x); } mint& operator+=(const mint& a) { if ((x += a.x) >= modc) x -= modc; return *this; } mint& operator-=(const mint& a) { if ((x += modc-a.x) >= modc) x -= modc; return *this; } mint& operator*=(const mint& a) { (x *= a.x) %= modc; return *this; } mint operator+(const mint& a) const { mint res(*this); return res+=a; } mint operator-(const mint& a) const { mint res(*this); return res-=a; } mint operator*(const mint& a) const { mint res(*this); return res*=a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } mint inv() const { return pow(modc-2); } mint& operator/=(const mint& a) { return (*this) *= a.inv(); } mint operator/(const mint& a) const { mint res(*this); return res/=a; } bool operator == (const mint& a) const{ return x == a.x; } friend ostream& operator<<(ostream& os, const mint& m){ os << m.x; return os; } friend istream& operator>>(istream& ip, mint &m) { ll t; ip >> t; m = mint(t); return ip; } ll val(){ return x; } }; struct UnionFind { int ngroup, N; vector par; vector siz; UnionFind(int _N) : N(_N), par(_N), siz(_N) { ngroup = _N; for(int i = 0; i < N; i++){ par[i] = i; siz[i] = 1; } } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } int unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return rx; ngroup--; if (siz[rx] > siz[ry]) swap(rx, ry); par[rx] = ry; siz[ry] += siz[rx]; return ry; } bool same(int x, int y) { int rx = root(x); int ry = root(y); return rx == ry; } int size(int x){ return siz[root(x)]; } int group_count(){ return ngroup; } vector> groups(){ vector rev(N); int nrt=0; for (int i=0; i> res(nrt); for (int i=0; i> N >> M; vector P(N+1); for (int i=1; i<=N; i++) P[i] = i; for (int i=0; i> T; vector S(T); for (int i=0; i> S[i]; tmp = P[S[T-1]]; for (int i=T-2; i>=0; i--){ P[S[i+1]] = P[S[i]]; } P[S[0]] = tmp; } UnionFind tree(N+1); for (int i=1; i<=N; i++){ tree.unite(P[i], i); } vector v; for (int i=1; i<=N; i++){ if (tree.root(i) == i) v.push_back(tree.size(i)); } mint ans=1; ll g=0; for (auto x : v){ g = gcd(g, x); ans *= x; } cout << ans * mod_exp(g, modc, modc-2) << endl; return 0; }