#include <bits/stdc++.h>
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
using namespace std;
int prim[1234567];
void makeprim() {
  for (int i = 2; i < 1234567; i++) {
    if (prim[i] == 0) {
      for (int j = i; j < 1234567; j += i) prim[j] = i;
    }
  }
}
int a[1234567];
int cnt[1234567];
int in[1234567];
int n, Q;
int que[1234567];
int fen(int x) {
  int ret = 0;
  while (x != 1) {
    int j = prim[x];
    que[ret++] = j;
    while (x % j == 0) x /= j;
  }
  return ret;
}
int Main() {
  ios_base::sync_with_stdio(0);
  makeprim();
  cin >> n >> Q;
  for (int i = 1; i <= int(n); ++i) cin >> a[i];
  long long ans = 0;
  int cao = 0;
  for (int QQ = 0; QQ < int(Q); ++QQ) {
    int x;
    cin >> x;
    int add = in[x] == 1 ? -1 : 1;
    cao += add;
    if (a[x] != 1) {
      int what = 0;
      int all = fen(a[x]);
      for (int s = 1; s <= int((1 << all) - 1); ++s) {
        int num = 0, tmp = 1;
        for (int j = 0; j < int(all); ++j)
          if (s & (1 << j)) {
            num++;
            tmp = tmp * que[j];
          }
        if (num % 2)
          what += cnt[tmp];
        else
          what -= cnt[tmp];
        cnt[tmp] += add;
      }
      if (in[x] == 1) what--;
      ans += what * add;
    }
    in[x] = 1 - in[x];
    cout << 1ll * cao * (cao - 1) / 2 - ans << endl;
  }
  return 0;
}
int main() { return Main(); }
