#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
const int N = 5e5 + 10;
int mu[N];
int pri[N];
bool ispri[N];
vector<int> v[N];
void getMo() {
  int tot = 0;
  mu[1] = 1;
  for (int i = 2; i < N; i++) {
    if (!ispri[i]) {
      pri[tot++] = i;
      mu[i] = -1;
    }
    for (int j = 0; j < tot && pri[j] * i < N; j++) {
      ispri[pri[j] * i] = 1;
      if (i % pri[j] == 0) {
        mu[i * pri[j]] = 0;
        break;
      }
      mu[i * pri[j]] = -mu[i];
    }
  }
}
int a[N], vis[N], cnt[N];
long long ans;
void add(int x) {
  int w = a[x];
  for (auto t : v[w]) {
    ans += 1LL * mu[t] * cnt[t];
    cnt[t]++;
  }
}
void del(int x) {
  int w = a[x];
  for (auto t : v[w]) {
    cnt[t]--;
    ans -= 1LL * mu[t] * cnt[t];
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  getMo();
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    vis[a[i]] = 1;
    mx = max(a[i], mx);
  }
  for (int i = 1; i <= mx; i++) {
    for (int j = i; j <= mx; j += i) {
      if (vis[j]) v[j].push_back(i);
    }
  }
  memset(vis, 0, sizeof vis);
  for (int i = 1; i <= m; i++) {
    int p;
    scanf("%d", &p);
    if (vis[p])
      del(p);
    else
      add(p);
    vis[p] = !vis[p];
    printf("%lld\n", ans);
  }
  return 0;
}
