#include <bits/stdc++.h>
using namespace std;
int n, q;
long long tans, ans, num;
int a[200005];
bool ful[200005];
int dv[500005];
void ff(int x, int pl, int typ) {
  if (!typ) dv[x]--;
  tans += pl * dv[x];
  if (typ) dv[x]++;
}
long long Get(int x, int typ) {
  if (typ)
    tans = num - 1;
  else
    tans = num;
  vector<int> get_dv;
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0) {
      while (x % i == 0) x /= i;
      get_dv.push_back(i);
    }
  if (x != 1) get_dv.push_back(x);
  int sz = 1 << get_dv.size();
  for (int i = 1; i < sz; i++) {
    int ii = i;
    int p = 1;
    int times = 0;
    for (int j = 0; j < get_dv.size(); j++)
      if (ii & 1) {
        p *= get_dv[j];
        times++;
        ii /= 2;
      } else
        ii /= 2;
    if (times % 2)
      ff(p, -1, typ);
    else
      ff(p, 1, typ);
  }
  return tans;
}
int main() {
  cin >> n >> q;
  for (int i = 0; i < n; i++) cin >> a[i];
  while (q--) {
    int x;
    cin >> x;
    ful[x] = !ful[x];
    if (ful[x])
      num++;
    else
      num--;
    if (ful[x])
      ans += Get(a[x - 1], ful[x]);
    else
      ans -= Get(a[x - 1], ful[x]);
    cout << ans << '\n';
  }
  return 0;
}
