#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;
long long ans, p[5000], cnt, sum, num[500010], a[maxn], rem;
bool flg[maxn], vis[maxn];
void split(long long a) {
  int t = sqrt(a), i = 1;
  sum = 0;
  while (a && i <= t) {
    ++i;
    if (a % i == 0) {
      p[sum++] = i;
      while (a % i == 0) a /= i;
    }
  }
  if (a > 1) p[sum++] = a;
}
void add(long long pos) {
  int t = (1 << sum) - 1;
  for (int i = 1; i <= t; ++i) {
    int tmp = 1, sign = -1;
    for (int j = 0; j < sum; ++j)
      if (i & (1 << j)) {
        tmp *= p[j];
        sign *= -1;
      }
    ans += sign * num[tmp];
    num[tmp]++;
  }
}
void del(long long pos) {
  int t = (1 << sum) - 1;
  for (int i = 1; i <= t; ++i) {
    int sign = -1, tmp = 1;
    for (int j = 0; j < sum; ++j)
      if (i & (1 << j)) {
        tmp *= p[j];
        sign *= -1;
      }
    num[tmp]--;
    ans -= sign * num[tmp];
  }
}
int main() {
  long long n, q, x;
  scanf("%I64d%I64d", &n, &q);
  for (int i = 1; i <= n; ++i) scanf("%I64d", &a[i]);
  while (q--) {
    scanf("%I64d", &x);
    split(a[x]);
    if (vis[x]) {
      del(x);
      vis[x] = 0;
      --rem;
    } else {
      add(x);
      vis[x] = 1;
      ++rem;
    }
    printf("%I64d\n", (rem * (rem - 1)) / 2 - ans);
  }
  return 0;
}
