#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6 + 100;
const long long mod = 1e9 + 7;
map<long long, long long> m;
long long l[maxn], f[maxn], cnt[maxn + 10];
bool isp[maxn];
vector<int> v;
int bit1(int a) {
  int b = 0;
  while (a) {
    b += (a % 2);
    a /= 2;
  }
  return b;
}
long long FFF(int a) {
  int b = 0;
  long long kk = 1;
  while (a) {
    if (a & 1) {
      kk *= v[b];
    }
    b++;
    a /= 2;
  }
  return kk;
}
int main() {
  int n, q;
  cin >> n >> q;
  long long res = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> l[i + 1];
  }
  int N = 0;
  for (int qq = 0; qq < q; qq++) {
    int ii;
    cin >> ii;
    int x = l[ii];
    if (m[ii] == 1) {
      m[ii] = 0;
      v.clear();
      for (int i = 2; i * i <= x; i++) {
        if (x % i == 0) {
          v.push_back(i);
          while (x % i == 0) x /= i;
        }
      }
      if (x > 1) v.push_back(x);
      res = N - 1;
      for (int i = 0; i < (1 << v.size()); i++) {
        long long k = FFF(i);
        cnt[k]--;
      }
      N--;
      for (int i = 1; i < (1 << v.size()); i++) {
        long long k = cnt[FFF(i)];
        if (bit1(i) % 2 == 1) k = -k;
        res += k;
      }
      ans -= res;
      cout << ans << endl;
      continue;
    }
    m[ii] = 1;
    N++;
    v.clear();
    for (int i = 2; i * i <= x; i++) {
      if (x % i == 0) {
        v.push_back(i);
        while (x % i == 0) x /= i;
      }
    }
    if (x > 1) v.push_back(x);
    res = N - 1;
    for (int i = 1; i < (1 << v.size()); i++) {
      long long k = cnt[FFF(i)];
      if (bit1(i) % 2 == 1) k = -k;
      res += k;
    }
    for (int i = 0; i < (1 << v.size()); i++) {
      long long k = FFF(i);
      cnt[k]++;
    }
    ans += res;
    cout << ans << endl;
  }
  return 0;
}
