#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010;
int b[maxn];
int a[maxn];
int s[maxn];
int n, q;
int prime[maxn], len;
void getprime() {
  len = 0;
  for (int i = 2; i < 3000; i++) {
    int ok = 0;
    for (int j = 0; !ok && prime[j] * prime[j] <= i && j < len; j++)
      if (i % prime[j] == 0) {
        ok = 1;
      }
    if (!ok) prime[len++] = i;
  }
}
int f[10];
int g[1000];
int h[1000];
int getf(int x) {
  int slen = 0, now = 0;
  while (x != 1 && now < len) {
    if (x % prime[now] == 0) {
      while (x % prime[now] == 0) x /= prime[now];
      h[1 << slen] = prime[now];
      f[slen++] = prime[now];
    }
    now++;
  }
  if (x != 1) h[1 << slen] = x, f[slen++] = x;
  slen = (1 << slen);
  h[0] = 1;
  g[0] = 1;
  for (int i = 1; i < slen; i++) {
    int k = i & (-i);
    g[i] = g[i - k] ^ 1;
    h[i] = h[k] * h[i - k];
  }
  return slen;
}
int main() {
  getprime();
  while (scanf("%d %d", &n, &q) != EOF) {
    memset(b, 0, sizeof(b));
    memset(s, 0, sizeof(s));
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    long long sum = 0;
    while (q--) {
      int x;
      scanf("%d", &x);
      int len = getf(a[x]);
      int ret = 0;
      if (s[x] == 0) {
        for (int i = 0; i < len; i++) {
          if (g[i])
            ret += b[h[i]];
          else
            ret -= b[h[i]];
          b[h[i]] += 1;
        }
        sum += ret;
      } else {
        for (int i = 0; i < len; i++) {
          if (g[i])
            ret += (b[h[i]] - 1);
          else
            ret -= (b[h[i]] - 1);
          b[h[i]] -= 1;
        }
        sum -= ret;
      }
      s[x] ^= 1;
      printf("%I64d\n", sum);
    }
  }
  return 0;
}
