#include <bits/stdc++.h>
using namespace std;
const long long Nmax = 5e5 + 5;
vector<long long> dv[Nmax];
long long a[Nmax];
long long p[Nmax];
long long cnt[Nmax];
long long n, q, num, ans;
bool flag[Nmax];
void era() {
  for (long long i = 2; i <= Nmax - 5; i++) {
    if (p[i]) continue;
    p[i] = i;
    for (long long j = i * i; j <= Nmax - 5; j += i) {
      p[j] = i;
    }
  }
}
void init() {
  for (long long i = 1; i <= n; i++) {
    long long res = a[i];
    while (res > 1) {
      long long d = p[res];
      while (res % d == 0) res /= d;
      dv[i].push_back(d);
    }
  }
}
long long getbit(long long x, long long i) { return (x >> i) & 1; }
long long numbit(long long x) {
  long long res = 0;
  while (x) {
    res += (x % 2);
    x >>= 1;
  }
  return res;
}
void update(long long i, long long val) {
  for (long long cur = 1; cur < (1 << dv[i].size()); cur++) {
    long long res = 1;
    for (long long j = 0; j < dv[i].size(); j++) {
      if (getbit(cur, j)) res *= dv[i][j];
    }
    cnt[res] += val;
  }
}
long long get(long long i) {
  long long ans = 0;
  for (long long cur = 1; cur < (1 << dv[i].size()); cur++) {
    long long res = 1;
    for (long long j = 0; j < dv[i].size(); j++) {
      if (getbit(cur, j)) res *= dv[i][j];
    }
    if (numbit(cur) & 1)
      ans += cnt[res];
    else
      ans -= cnt[res];
  }
  return ans;
}
signed main() {
  era();
  cin >> n >> q;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  init();
  for (long long i = 1; i <= q; i++) {
    long long x;
    cin >> x;
    if (flag[x]) {
      if (a[x] == 1) {
        ans -= --num;
        cnt[1]--;
      } else {
        ans -= num - get(x);
        update(x, -1);
        num--;
      }
      flag[x] = false;
    } else {
      if (a[x] == 1) {
        ans += num++;
        cnt[1]++;
      } else {
        ans += num - get(x);
        update(x, 1);
        num++;
      }
      flag[x] = true;
    }
    cout << ans << "\n";
  }
  return 0;
}
