#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int MOD = 1e9 + 7;
const int N = 5e5 + 10, M = 5e5;
int n, q, x, t[N], re[1 << 10], c[N] = {0}, h[N], top = 0, a[N];
vector<int> g[N];
long long ans = 0;
void del(int x) {
  h[x] = 0;
  ans -= --top;
  if (a[x] == 1) return;
  int m1 = g[a[x]].size();
  re[0] = 1;
  for (auto i = 0; i < m1; i++) re[1 << i] = g[a[x]][i];
  for (auto i = 1; i < 1 << m1; i++) {
    re[i] = re[i & -i] * re[i - (i & -i)];
    c[re[i]]--;
    if (__builtin_popcount(i) % 2)
      ans += c[re[i]];
    else
      ans -= c[re[i]];
  }
}
void add(int x) {
  h[x] = 1;
  ans += top++;
  if (a[x] == 1) return;
  int m1 = g[a[x]].size();
  re[0] = 1;
  for (auto i = 0; i < m1; i++) re[1 << i] = g[a[x]][i];
  for (auto i = 1; i < 1 << m1; i++) {
    re[i] = re[i & -i] * re[i - (i & -i)];
    if (__builtin_popcount(i) % 2)
      ans -= c[re[i]];
    else
      ans += c[re[i]];
    c[re[i]]++;
  }
}
int main() {
  for (auto i = 2; i <= M; i++)
    if (!t[i])
      for (int j = i; j <= M; j += i) t[j] = i;
  for (auto i = 2; i <= M; i++) {
    int x = i;
    while (x > 1) {
      int tmp = t[x];
      g[i].push_back(tmp);
      while (x % tmp == 0) x /= tmp;
    }
  }
  scanf("%d%d", &n, &q);
  for (auto i = 1; i <= n; i++) scanf("%d", a + i);
  while (q--) {
    scanf("%d", &x);
    if (h[x])
      del(x);
    else
      add(x);
    printf("%lld\n", ans);
  }
}
