- /* Author : Triet Do Thanh - FPT University */ 
-   
- #include <bits/stdc++.h> 
-   
- #define endl           '\n' 
- #define int            long long 
-   
- using namespace        std; 
-   
- typedef pair<int, int> ii; 
-   
- const int       N      = 3e6 + 7; 
- const long long oo     = 1e18 + 7; 
- const long long MOD    = 1e9 + 7; 
-   
- int n; 
- int a[N]; 
- vector<int>pos[N], p[N]; 
-   
- int pointer[N]; 
-   
- int d[N * 2]; 
-   
- void sieve() { 
-    d[0] = d[1] = 1; 
-    for (int i = 2; i * i <= N; ++i) { 
-       if (d[i] == 0) { 
-          for (int j = i; j * i <= N; ++j) d[i * j] = 1; 
-       } 
-    } 
- } 
-   
- void solve() { 
-    cin >> n; 
-    for (int i = 1; i <= n; ++i) cin >> a[i]; 
-    sieve(); 
-    for (int i = 1; i <= n; ++i) { 
-       for (int div = 2; div <= a[i]; ++div) { 
-          if (d[a[i]] == 0) { 
-             pos[a[i]].push_back(i); 
-             p[i].push_back(a[i]); 
-             a[i] = 1; 
-             break; 
-          } 
-          if (a[i] % div == 0)  { 
-             pos[div].push_back(i); 
-             p[i].push_back(div); 
-             while (a[i] % div == 0) { 
-                a[i] /= div; 
-             } 
-          } 
-       } 
-    } 
-    //for (int &it : pos[2]) cout << it << ' '; 
-   
-    for (int i = 1; i <= n; ++i) { 
-       int ans = oo; 
-       int res = -1; 
-       for (int div : p[i]) { 
-          if ((int)pos[div].size() < 2) continue; 
-          int vt = lower_bound(pos[div].begin(), pos[div].end(), i) - pos[div].begin(); 
-          if (vt == 0) { 
-             if (pos[div][vt + 1] - pos[div][vt] < ans) {  
-                ans = pos[div][vt + 1] - pos[div][vt]; 
-                res = pos[div][vt + 1]; 
-             } 
-          } 
-          else if (vt == (int)pos[div].size() - 1) { 
-             if (pos[div][vt] - pos[div][vt - 1] <= ans) {  
-                ans = pos[div][vt] - pos[div][vt - 1]; 
-                res = pos[div][vt - 1]; 
-             } 
-          } 
-          else { 
-             if (pos[div][vt + 1] - pos[div][vt] < ans) {  
-                ans = pos[div][vt + 1] - pos[div][vt]; 
-                res = pos[div][vt + 1]; 
-             } 
-             if (pos[div][vt] - pos[div][vt - 1] <= ans) {  
-                ans = pos[div][vt] - pos[div][vt - 1]; 
-                res = pos[div][vt - 1]; 
-             } 
-          } 
-       } 
-       cout << res <<' '; 
-    } 
-   
- } 
-   
- #define TASK "test" 
-   
- signed main() 
- { 
-    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); 
-    if (fopen("input.txt", "r")) { 
-       freopen("input.txt", "r", stdin); 
-       freopen("output.txt", "w", stdout); 
-    } 
-    solve(); 
-    return 0; 
- }