#include <bits/stdc++.h>
using namespace std;
int fact[500005];
void criba() {
  for (int i = 2; i * i < 500005; i++)
    if (fact[i] == 0)
      for (int j = i * i; j < 500005; j += i) fact[j] = i;
  for (int i = 2; i < 500005; i++)
    if (fact[i] == 0) fact[i] = i;
}
bool vis[500005];
int F[500005], a[500005];
int mask[1 << 9], primes[9];
vector<pair<int, int> > G[500005];
int main() {
  int n, q;
  criba();
  while (cin >> n >> q) {
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      int num = a[i], top = 0;
      while (num > 1) {
        int f = fact[num];
        while (num % f == 0) num /= f;
        primes[top++] = f;
      }
      mask[0] = 1;
      for (int j = 1, l; j < (1 << top); j++) {
        l = 31 - __builtin_clz(j & -j);
        mask[j] = mask[j ^ (1 << l)] * primes[l];
        if (__builtin_popcount(j) % 2 == 0)
          G[i].push_back(make_pair(mask[j], 0));
        else
          G[i].push_back(make_pair(mask[j], 1));
      }
    }
    long long pos, cur = 0, last = 0;
    long long ans, val, id;
    for (int i = 0; i < q; i++) {
      scanf("%d", &pos);
      pos--;
      ans = cur;
      if (vis[pos]) {
        for (int j = 0; j < G[pos].size(); j++) {
          val = G[pos][j].first;
          id = G[pos][j].second;
          if (id)
            ans -= F[val];
          else
            ans += F[val];
          F[val]--;
        }
        cur--;
      } else {
        for (int j = 0; j < G[pos].size(); j++) {
          val = G[pos][j].first;
          id = G[pos][j].second;
          if (id)
            ans -= F[val];
          else
            ans += F[val];
          F[val]++;
        }
        cur++;
      }
      if (vis[pos] && a[pos] == 1) ans--;
      if (vis[pos])
        ans = last - ans;
      else
        ans = last + ans;
      vis[pos] = 1 - vis[pos];
      printf("%I64d\n", ans);
      last = ans;
    }
  }
}
