#include <bits/stdc++.h>
const int N = 500005;
using namespace std;
int np[N], a[N], cnt[N];
int save[N];
bool chk[N];
bool was[N];
bool ok[N];
vector<int> F[N];
int long long ans, inSetCnt;
int n, nQuery;
void update(int idx, int sign) {
  inSetCnt += sign;
  if (sign == -1) {
    for (int factor : F[idx])
      if (ok[factor]) save[factor] += sign;
  }
  for (int factor : F[idx])
    if (ok[factor]) {
      if (cnt[factor])
        ans += save[factor] * sign;
      else
        ans -= save[factor] * sign;
    }
  if (sign == 1) {
    for (int factor : F[idx])
      if (ok[factor]) save[factor] += sign;
  }
  cout << inSetCnt * (inSetCnt - 1) / 2 - ans << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> nQuery;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    for (int j = 1; j * j <= a[i]; ++j)
      if (a[i] % j == 0) {
        F[i].push_back(j);
        if (j * j != a[i]) F[i].push_back(a[i] / j);
      }
  }
  for (int i = 2; i * i < N; ++i)
    if (!np[i])
      for (int j = i * i; j < N; j += i) np[j] = i;
  for (int i = 1; i < N; ++i)
    if (!np[i]) np[i] = i;
  for (int i = 2; i < N; ++i) {
    int j = i;
    cnt[i] = 0;
    ok[i] = 1;
    vector<int> A;
    while (j > 1) {
      if (!chk[np[j]]) {
        chk[np[j]] = 1;
        cnt[i] ^= 1;
        A.push_back(np[j]);
      } else {
        ok[i] = 0;
        break;
      }
      j /= np[j];
    }
    while (!A.empty()) {
      chk[A.back()] = 0;
      A.pop_back();
    }
  }
  int x;
  while (nQuery--) {
    cin >> x;
    if (was[x]) {
      was[x] = 0;
      update(x, -1);
    } else {
      was[x] = 1;
      update(x, 1);
    }
  }
  return 0;
}
