#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e6 + 10;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
const double eps = 1e-9;
long long ans;
int d[maxn], pr[maxn], sz, there[maxn];
void prime(int x) {
  sz = 0;
  for (int i = 2; i * i <= x; ++i) {
    if (x % i == 0) {
      x /= i;
      pr[sz++] = i;
      while (x % i == 0) x /= i;
    }
  }
  if (x > 1) pr[sz++] = x;
  return;
}
void rec(int v, int x, int cnt, int val) {
  if (v == sz) {
    if (val < 0) d[x] += val;
    if (cnt % 2)
      ans -= d[x] * val;
    else
      ans += d[x] * val;
    if (val > 0) d[x] += val;
    return;
  }
  rec(v + 1, x, cnt, val);
  rec(v + 1, x * pr[v], cnt + 1, val);
  return;
}
int a[maxn];
void add(int x) {
  there[x] = true;
  prime(a[x]);
  rec(0, 1, 0, 1);
  return;
}
void del(int x) {
  there[x] = false;
  prime(a[x]);
  rec(0, 1, 0, -1);
  return;
}
int n, q, x;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= q; ++i) {
    cin >> x;
    if (there[x])
      del(x);
    else
      add(x);
    cout << ans << '\n';
  }
  return 0;
}
