#include <bits/stdc++.h>
using namespace std;
int getprim(int n, vector<int> &prim) {
  int i;
  long long j;
  char *a;
  if (n < 3) return 0;
  a = (char *)calloc(n + 2, sizeof(char));
  a[0] = a[1] = 1;
  prim.push_back(i = 2);
  i = 3;
  while (i < n) {
    prim.push_back(i);
    for (j = i * (long long)i; j < n; j += i + i) a[j] = 1;
    do i += 2;
    while (a[i]);
  }
  free(a);
  return (int)prim.size();
}
vector<int> allprim;
int factorize(int a, vector<int> &f) {
  int i = 0;
  for (int p = allprim[i]; p * p <= a; p = allprim[++i]) {
    if (a % p == 0) f.push_back(p);
    while (a % p == 0) a /= p;
  }
  if (1 < a) f.push_back(a);
  return (int)f.size();
}
int main() {
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  getprim(1000, allprim);
  long long ngcd = 0;
  long long nn = 0;
  int ff[500001] = {0};
  vector<int> mark(n, 0);
  for (int l = 0; l < q; ++l) {
    int k;
    cin >> k;
    --k;
    int sign = 1 - 2 * mark[k];
    vector<int> prim;
    int n = factorize(a[k], prim);
    for (int i = 1; i < (1 << n); ++i) {
      int x = 1;
      int nbit = 0;
      for (int j = 0; j < n; ++j)
        if ((i >> j) & 1) {
          x *= prim[j];
          ++nbit;
        }
      if (nbit & 1)
        ngcd += sign * ff[x];
      else
        ngcd -= sign * ff[x];
      ff[x] += sign;
    }
    if (a[k] != 1 && sign < 0) ngcd++;
    mark[k] = 1 - mark[k];
    nn += 2 * mark[k] - 1;
    long long res = nn * (nn - 1) / 2 - ngcd;
    cout << res << "\n";
  }
  return 0;
}
