#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 5e5 + 10;
const int maxv = 5e5 + 10;
const double eps = 1e-9;
int maxprime[maxv];
int mu[maxv];
bool on[maxv];
int d[maxv];
int a[maxv];
int n, q;
long long ans;
void Init() {
  memset(maxprime, -1, sizeof maxprime);
  for (int i = 1; i < maxv; i++) mu[i] = 1;
  for (int i = 2; i < maxv; i++) {
    if (~maxprime[i]) continue;
    for (int j = 1, v = i; v < maxv; j++, v += i) {
      maxprime[v] = i;
      mu[v] = j % i == 0 ? 0 : -mu[v];
    }
  }
}
bool Add(int x) {
  int fac[6], facn = 0;
  while (x > 1) {
    int p = maxprime[x];
    fac[facn++] = p;
    do x /= p;
    while (x % p == 0);
  }
  int MAX = 1 << facn;
  for (int i = 0; i < MAX; i++) {
    int t = i, v = 1;
    for (int j = 0; j < facn; j++, t >>= 1) {
      if (t & 1) v *= fac[j];
    }
    ans += d[v] * mu[v];
    ++d[v];
  }
  return true;
}
bool Remove(int x) {
  int fac[6], facn = 0;
  while (x > 1) {
    int p = maxprime[x];
    fac[facn++] = p;
    do x /= p;
    while (x % p == 0);
  }
  int MAX = 1 << facn;
  for (int i = 0; i < MAX; i++) {
    int t = i, v = 1;
    for (int j = 0; j < facn; j++, t >>= 1) {
      if (t & 1) v *= fac[j];
    }
    --d[v];
    ans -= d[v] * mu[v];
  }
}
int main() {
  Init();
  while (scanf("%d%d", &n, &q) != EOF) {
    memset(on, 0, sizeof on);
    memset(d, 0, sizeof d);
    ans = 0;
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 0; i < q; i++) {
      int x;
      scanf("%d", &x);
      on[x] = on[x] ? Remove(a[x]), false : Add(a[x]), true;
      printf("%I64d\n", ans);
    }
  }
  return 0;
}
