#include <bits/stdc++.h>
using namespace std;
const int inf = 2147483647;
long long isp[555555];
void shai() {
  for (long long i = 2; i <= 500000; i++) {
    if (isp[i] == 0) {
      for (long long j = i; j <= 500000; j += i) {
        isp[j] = i;
      }
    }
  }
}
long long n, q;
long long a[222222];
vector<long long> my;
bool is[222222];
long long res;
long long cur[555555];
void dfs(long long lvl, long long nw, long long num, bool init) {
  if (lvl == my.size()) {
    if (init) {
      cur[nw]--;
    }
    if (init ^ (num % 2 != 0)) {
      res -= cur[nw];
    } else {
      res += cur[nw];
    }
    if (!init) {
      cur[nw]++;
    }
  } else {
    dfs(lvl + 1, nw, num, init);
    dfs(lvl + 1, nw * my[lvl], num + 1, init);
  }
}
int main() {
  shai();
  cin >> n >> q;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  while (q--) {
    long long t;
    cin >> t;
    my.clear();
    long long num = a[t];
    while (num > 1) {
      long long pr = isp[num];
      my.push_back(pr);
      while (num % pr == 0) {
        num /= pr;
      }
    }
    dfs(0, 1, 0, is[t]);
    is[t] = !is[t];
    cout << res << endl;
  }
  return 0;
}
