#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 5;
long long a[maxn];
vector<long long> D[maxn];
map<long long, long long> M;
bitset<maxn> f;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, q;
  cin >> n >> q;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    long long k = a[i];
    for (long long j = 2; j * j <= k; j++) {
      if (k % j == 0) {
        D[i].push_back(j);
        while (k % j == 0) k /= j;
      }
    }
    if (k > 1) D[i].push_back(k);
  }
  long long ans = 0;
  while (q--) {
    long long id;
    cin >> id;
    id--;
    long long m = D[id].size();
    long long P[1 << m];
    P[0] = 1;
    if (!f[id]) {
      for (long long mask = 0; mask < (1 << m); mask++) {
        if (mask)
          P[mask] = D[id][__builtin_ctz(mask)] * P[mask - (mask & -mask)];
        if (__builtin_popcount(mask) % 2)
          ans -= M[P[mask]];
        else
          ans += M[P[mask]];
        M[P[mask]]++;
      }
    } else {
      for (long long mask = 0; mask < (1 << m); mask++) {
        if (mask)
          P[mask] = D[id][__builtin_ctz(mask)] * P[mask - (mask & -mask)];
        M[P[mask]]--;
        if (__builtin_popcount(mask) % 2)
          ans += M[P[mask]];
        else
          ans -= M[P[mask]];
      }
    }
    f[id] = !f[id];
    cout << ans << '\n';
  }
}
