#include <bits/stdc++.h>
using namespace std;
int a[300000];
vector<pair<int, int> > fac[300000];
int co[100];
int d[300000];
int dd[600000];
int now;
long long tot;
int diff;
int c(int x, int y) {
  int i, ret;
  ret = 1;
  for (i = 0; i < y; i++) {
    ret *= (x - i);
    ret /= (i + 1);
  }
  return ret;
}
void search(int x, int ind, int v) {
  int i, tmpnow, tmpdiff;
  if (x == fac[ind].size()) {
    dd[now] += v;
    tot += co[diff] * dd[now];
    return;
  }
  tmpnow = now;
  tmpdiff = diff;
  for (i = 0; i <= 1; i++) {
    search(x + 1, ind, v);
    if (i == fac[ind][x].second) break;
    now *= fac[ind][x].first;
    if (i == 0) diff++;
  }
  now = tmpnow;
  diff = tmpdiff;
}
void rem1(int x) {
  now = 1;
  search(0, x, -1);
}
void add1(int x) {
  now = 1;
  search(0, x, 1);
}
int cal(int x) {
  tot = 0;
  now = 1;
  diff = 0;
  search(0, x, 0);
  return tot;
}
int main() {
  int i, j, n, q, x, tmp, cnt;
  long long ans;
  co[0] = 1;
  co[1] = -1;
  for (i = 2; i <= 15; i++) {
    co[i] = 0;
    for (j = 0; j < i; j++) co[i] += co[j] * c(i, j);
    co[i] = -co[i];
  }
  scanf("%d%d", &n, &q);
  for (i = 0; i < n; i++) {
    fac[i].clear();
    scanf("%d", &a[i]);
    tmp = a[i];
    for (j = 2; j * j <= tmp; j++) {
      cnt = 0;
      while (tmp % j == 0) {
        tmp /= j;
        cnt++;
      }
      if (cnt > 0) fac[i].push_back(make_pair(j, cnt));
    }
    if (tmp > 1) {
      fac[i].push_back(make_pair(tmp, 1));
    }
  }
  memset(d, 0, sizeof(d));
  memset(dd, 0, sizeof(dd));
  ans = 0;
  for (i = 0; i < q; i++) {
    scanf("%d", &x);
    x--;
    tmp = d[x];
    if (tmp == 1) {
      rem1(x);
    }
    if (tmp == 1)
      ans -= cal(x);
    else
      ans += cal(x);
    if (tmp == 0) {
      add1(x);
    }
    d[x] = 1 - d[x];
    cout << ans << endl;
  }
  return 0;
}
