#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int n, m, x, tot;
int a[maxn];
bool check[maxn];
vector<int> V[maxn];
int p[500010], cnt = 0;
bool vis[500010];
int Num[500010];
long long ans = 0;
void Get_Prime() {
  for (int i = 2; i <= 500000; ++i) {
    if (!vis[i]) p[++cnt] = i;
    for (int j = 1; j <= cnt; ++j) {
      if (1LL * p[j] * i > 500000) break;
      vis[p[j] * i] = true;
      if (i % p[j] == 0) break;
    }
  }
  return;
}
void push(int now) {
  int x = a[now], lim = (int)(sqrt(x));
  for (int i = 1; i <= cnt; ++i) {
    if (p[i] > lim) break;
    if (x % p[i] == 0) {
      V[now].push_back(p[i]);
      while (x % p[i] == 0) x /= p[i];
      if (x == 1) break;
    }
  }
  if (x > 1) V[now].push_back(x);
}
void add(int now) {
  int k = V[now].size();
  for (int i = 0; i < (1 << k); ++i) {
    int bit = 0, o = 1;
    for (int j = 0; j < k; ++j)
      if (i >> j & 1) bit++, o *= V[now][j];
    if (bit & 1)
      ans -= Num[o];
    else
      ans += Num[o];
    Num[o]++;
  }
  return;
}
void del(int now) {
  int k = V[now].size();
  for (int i = 0; i < (1 << k); ++i) {
    int bit = 0, o = 1;
    for (int j = 0; j < k; ++j)
      if (i >> j & 1) bit++, o *= V[now][j];
    Num[o]--;
    if (bit & 1)
      ans += Num[o];
    else
      ans -= Num[o];
  }
  return;
}
int main() {
  scanf("%d%d", &n, &m);
  Get_Prime();
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), push(i);
  for (int i = 1; i <= m; ++i) {
    scanf("%d", &x);
    if (check[x])
      del(x), check[x] = false;
    else
      add(x), check[x] = true;
    cout << ans << endl;
  }
  return 0;
}
