#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
const int Max = 5e5;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
vector<int> prime[N];
int a[N], cnt[N];
inline void init() {
  for (int i = 2; i <= Max; ++i) {
    if (prime[i].empty()) {
      for (int j = i; j <= Max; j += i) prime[j].push_back(i);
    }
  }
}
inline int ask(int x) {
  static vector<int> tmp;
  tmp = prime[x];
  int all = tmp.size(), ans = 0, sz = all;
  all = (1 << all) - 1;
  for (int i = 0; i <= all; ++i) {
    int y = 1, f = 1;
    for (int k = 0; k < sz; ++k) {
      if ((i >> k) & 1) y *= tmp[k], f *= -1;
    }
    ans += f * cnt[y];
  }
  tmp.clear();
  return ans;
}
inline void insert(int x, int y) {
  static vector<int> tmp;
  tmp = prime[x];
  int sz = tmp.size(), all = (1 << sz) - 1;
  for (int i = 0; i <= all; ++i) {
    int z = 1;
    for (int k = 0; k < sz; ++k) {
      if ((i >> k) & 1) z *= tmp[k];
    }
    cnt[z] += y;
  }
  tmp.clear();
}
bool in[N];
int main() {
  int n, q;
  init();
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  long long ans = 0;
  while (q--) {
    int x;
    scanf("%d", &x);
    if (!in[x]) {
      ans += ask(a[x]);
      insert(a[x], 1);
      in[x] = 1;
    } else {
      insert(a[x], -1);
      ans -= ask(a[x]);
      in[x] = 0;
    }
    cout << ans << endl;
  }
}
