#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int N;
    int Ai[100];
    int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
    int p_best = -1, p_best_count = 0, p_count;
    
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> Ai[i];
    }
    
    for (int j = 0; j < sizeof(primes) / sizeof(int); j++) {
        p_count = 0;
        for (int i = 0; i < N; i++) {
            if (Ai[i] == 1) continue;
            if (Ai[i] % primes[j] == 0) {
                p_count++;
                do {
                    Ai[i] /= primes[j];
                } while (Ai[i] % primes[j] == 0);
            }
        }
        if (p_count > p_best_count) {
            p_best = primes[j];
            p_best_count = p_count;
        }
    }
    
    sort(Ai, Ai + N);
    
    int curr_p = 1;
    for (int i = 0; i < N; i++) {
        if (Ai[i] == 1) continue;
        if (Ai[i] > curr_p) {
            if (p_count > p_best_count) {
                p_best = curr_p;
                p_best_count = p_count;
            }
            curr_p = Ai[i];
            p_count = 1;
        } else {
            p_count++;
        }
    }
    if (p_count > p_best_count) {
        p_best = curr_p;
        p_best_count = p_count;
    }
    
    cout << p_best;
    
    return 0;
}
#include<iostream>
#include<cstdio>
#include<ctime>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<vector>
#include<iomanip>
#include<fstream>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<sstream>
using namespace std;
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0)
//string::npos

const double pi = 3.141592653589;
const int maxn = 200002;
const int maxm = 26;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
typedef long long ll;

ll ksm(int a, int k){
    ll res = 1;
    while(k){
        if(k&1) res = (ll)res*a%mod;
        a = (ll)a*a%mod;
        k >>= 1;
    }
    return res;
}
int nxt[maxn];
int vis[maxn];
int ans, p, ring, n;

void solve(){
    for(int i = 1; i <= n; ++i){
        if(vis[i]) continue;
        p = i;
        ++ring;
        while(vis[p] == 0){
            vis[p] = ring;
            p = nxt[p];
            if(vis[p] == ring) ++ans;
        }
    }
}


int main(){
    sync;

    cin >> n;
    ring = 1;
    for(int i = 1; i <= n; ++i){
        cin >> nxt[i];
        if(nxt[i] == i){
            vis[i] = ring++;
            ans++;
        }
    }
    solve();
    cout << ksm(2, ans)-1 << endl;


    return 0;
}



