// Nurstan Duisengaliev(REALBOY)
// не, не надо меня узнавать 
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")*/                   
      
#include <bits/stdc++.h>
 
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define pll pair <ll, ll>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) (int)x.size()
 
using namespace std;
 
const int N = (int)2e5 + 123;
const int mod = 998244353;
const ll INF = (ll)1e18 + 1;
int n, a[N];
vector <int> g[N];
int used[N];
int par[N];
int kol = 0;
bool check = 0;
void Dfs (int v) {
	used[v] = 1;
	for (auto to : g[v]) {
		if (!used[to]) {
			Dfs (to);
		}
		else if (used[to] == 1) {
			check = 1;
		}
	}
	used[v] = 2;	
}
void solve () {
	cin >> n;
	for (int i = 1; i <= n; i ++) cin >> a[i]; 
	for (int i = 1; i <= n; i ++) {
		g[i].pb	(a[i]);
	}
	for (int i = 1; i <= n; i ++) {
		if (!used[i]) {
			check = 0;
			Dfs (i);
			kol += check;
		}		
	}
	ll ans = 1;
	for (int i = 1; i <= kol; i ++) {
		ans *= 2;
		ans %= mod;
	}
	cout << (ans + mod - 1) % mod;
}   	
 
main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int TT = 1;
//    cin >> TT;
	while (TT --) {
		solve ();
	}
	return 0;	                                    
}
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T>>;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

ll pr[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};

//head



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vi x(n);
  rep(i, n) cin >> x[i];
  ll ans = INT64_MAX;
  rep(i, 1<<15) {
    ll now = 1;
    bool ok2 = true;
    rep(j, n) {
      bool ok = false;
      rep(k, 15) if(i>>k&1 and x[j]%pr[k] == 0) ok = true;
      if(not ok) ok2 = false;
    }
    if(ok2) {
      ll u = 1;
      rep(k, 15) if(i>>k&1) u *= pr[k];
      chmin(ans, u);
    }
  }
  cout << ans << endl;
}