#include <bits/stdc++.h>
using namespace std;
int a[200100];
bool pres[200010] = {0};
vector<int> pf[500100];
int p[500010];
int cnt[500010];
int n;
void pre() {
  int MAXN = 500000;
  for (int i = 1; i <= MAXN; i++) p[i] = i;
  for (int i = 2; i <= MAXN; i++)
    if (p[i] == i)
      for (int j = i + i; j <= MAXN; j += i) p[j] = i;
  for (int i = 2; i <= MAXN; i++) {
    int ii = i, w = p[i];
    while (ii % w == 0) ii /= w;
    vector<int> f = pf[ii];
    f.push_back(w);
    pf[i] = f;
  }
}
int val(vector<int> v, int x) {
  int res = 1, i = 0;
  while (x) {
    if (x & 1) res *= v[i];
    x /= 2;
    i++;
  }
  return res;
}
int cntx(int x) {
  int res = 0;
  while (x) {
    res += (x & 1);
    x /= 2;
  }
  return res;
}
long long int res = 0;
long long int tot = 0;
void add(int x) {
  pres[x] = 1;
  x = a[x];
  if (x != 1) {
    vector<int> v = pf[x];
    int k = v.size();
    int w = 1 << k;
    long long int presres = 0;
    for (int i = 1; i < w; i++) {
      int m = val(v, i);
      if (cntx(i) & 1)
        presres -= cnt[m];
      else
        presres += cnt[m];
    }
    presres += tot;
    res += presres;
  } else
    res += tot;
  for (int i = 1; i * i <= x; i++) {
    if (i * i == x) {
      cnt[i]++;
      continue;
    }
    if (x % i == 0) {
      cnt[i]++;
      cnt[x / i]++;
    }
  }
  tot++;
}
void rem(int x) {
  pres[x] = 0;
  x = a[x];
  if (x != 1) {
    vector<int> v = pf[x];
    int k = v.size();
    int w = 1 << k;
    long long int presres = 0;
    for (int i = 1; i < w; i++) {
      int m = val(v, i);
      if (cntx(i) & 1)
        presres -= cnt[m];
      else
        presres += cnt[m];
    }
    presres += tot;
    res -= presres;
  } else {
    res -= tot;
    res++;
  }
  tot--;
  for (int i = 1; i * i <= x; i++) {
    if (i * i == x) {
      cnt[i]--;
      continue;
    }
    if (x % i == 0) {
      cnt[i]--;
      cnt[x / i]--;
    }
  }
}
int main() {
  pre();
  int q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  int x;
  for (int i = 1; i <= q; i++) {
    scanf("%d", &x);
    if (pres[x]) {
      rem(x);
    } else
      add(x);
    printf("%I64d\n", res);
  }
}
