#include <bits/stdc++.h>
using namespace std;
const int Maxn = 2e5 + 50, Maxa = 5e5 + 50;
int n, q, K, a[Maxn], cnt, c[6], vis[Maxn], d[Maxa], mu[Maxa], mp[Maxa];
long long ans;
void init() {
  int i, j, tmp;
  memset(mp, -1, sizeof(mp));
  for (i = 1; i < Maxa; i++) mu[i] = 1;
  for (i = 2; i < Maxa; i++) {
    if (~mp[i]) continue;
    for (j = 1, tmp = i; tmp < Maxa; j++, tmp += i) {
      mp[tmp] = i;
      mu[tmp] = j % i == 0 ? 0 : -mu[tmp];
    }
  }
}
void work(int x, int g) {
  int i, j;
  int fac[6], num = 0;
  while (x > 1) {
    int p = mp[x];
    fac[num++] = p;
    while (x % p == 0) x /= p;
  }
  for (i = 0; i < (1 << num); i++) {
    int t = i, v = 1;
    for (j = 0; j < num; j++, t >>= 1)
      if (t & 1) v *= fac[j];
    if (g) {
      ans += d[v] * mu[v];
      d[v]++;
    } else {
      d[v]--;
      ans -= d[v] * mu[v];
    }
  }
}
int main() {
  int i;
  init();
  scanf("%d%d", &n, &q);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= q; i++) {
    int tmp, g;
    scanf("%d", &tmp);
    if (vis[tmp])
      g = 0, vis[tmp] = 0;
    else
      g = 1, vis[tmp] = 1;
    work(a[tmp], g);
    printf("%lld\n", ans);
  }
  return 0;
}
