/*******************************************************
5) GFG — Nearest Left Index That Divides Current Element

Problem:
For each i, find nearest j<i such that A[i] % A[j] == 0, else -1.

Idea:
- For x=A[i], enumerate all divisors d of x.
- If we saw d earlier at lastIndex[d], then that's a valid j.
- Take maximum j among all divisors -> nearest to left.

Time: O(n * sqrt(maxA)) expected
*******************************************************/

#include <bits/stdc++.h>                 // standard CP header
using namespace std;                     // use std names directly

int main() {                             // program start
    ios::sync_with_stdio(false);         // fast I/O
    cin.tie(nullptr);                    // fast I/O

    int n;                               // array size
    cin >> n;                            // read n
    vector<int> A(n);                    // array
    for (int i = 0; i < n; i++) cin >> A[i]; // read elements

    unordered_map<int,int> lastIndex;    // lastIndex[value] = most recent index where value appeared
    lastIndex.reserve((size_t)n * 2);    // reserve to reduce rehashing (performance trick)

    for (int i = 0; i < n; i++) {        // process from left to right
        int x = A[i];                    // current value
        int best = -1;                   // best answer (nearest index), -1 if none

        for (int d = 1; 1LL * d * d <= x; d++) { // enumerate divisors up to sqrt(x)
            if (x % d) continue;         // if d is not a divisor, skip

            int d1 = d;                  // first divisor
            int d2 = x / d;              // paired divisor

            auto it1 = lastIndex.find(d1); // see if d1 was seen
            if (it1 != lastIndex.end()) best = max(best, it1->second); // update nearest index

            auto it2 = lastIndex.find(d2); // see if d2 was seen
            if (it2 != lastIndex.end()) best = max(best, it2->second); // update nearest index
        }

        cout << best << (i + 1 == n ? '\n' : ' '); // print answer (0-based index)

        lastIndex[x] = i;                // update last seen index for x
    }

    return 0;                            // done
}