#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng((unsigned long long)new char);
const double eps = 1e-10;
const int maxn = 500010;
const long long INF = 1e8;
const int mod = 1e9 + 7;
bool vis[maxn];
vector<int> prime;
void sieve(int n) {
  int m = sqrt(n + 0.5);
  memset(vis, 0, sizeof(vis));
  for (int i = 2; i <= m; ++i) {
    if (!vis[i])
      for (long long j = (long long)i * i; j < n; j += i) {
        vis[j] = 1;
      }
  }
}
void gen_prime(int n) {
  sieve(n);
  prime.clear();
  for (int i = 2; i < n; ++i) {
    if (!vis[i]) prime.push_back(i);
  }
}
vector<int> v[maxn];
int n, q, a[maxn];
bool in[maxn];
int cnt[maxn];
long long ans = 0;
int sum = 0;
void tackle(int x, int di) {
  int l = v[x].size();
  for (int t = (1); t < (1 << l); ++t) {
    int u = 1;
    for (int i = (0); i < (l); ++i)
      if (t & (1 << i)) u *= v[x][i];
    cnt[u] += di;
  }
}
long long cal(int x) {
  long long ans = 0;
  int l = v[x].size();
  for (int t = (1); t < (1 << l); ++t) {
    int u = 1, s = 0;
    for (int i = (0); i < (l); ++i)
      if (t & (1 << i)) u *= v[x][i], ++s;
    if (s & 1)
      ans += cnt[u];
    else
      ans -= cnt[u];
  }
  if (ans) --ans;
  return sum - ans - 1;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> q;
  for (int t = (0); t < (n); ++t) cin >> a[t];
  memset(in, 0, sizeof(in));
  gen_prime(maxn);
  for (int t = (2); t < (maxn); ++t) {
    int r = t;
    for (int i = (0); i < (prime.size()); ++i) {
      if (prime[i] * prime[i] > t) break;
      if (r % prime[i] == 0) {
        v[t].push_back(prime[i]);
        while (r % prime[i] == 0) r /= prime[i];
      }
      if (r == 1) break;
    }
    if (r > 1) v[t].push_back(r);
    for (auto r : v[t]) assert(!vis[r]);
  }
  memset(cnt, 0, sizeof(cnt));
  while (q--) {
    int x;
    cin >> x;
    --x;
    if (in[x]) {
      ans -= cal(a[x]);
      in[x] = 0;
      --sum;
      tackle(a[x], -1);
    } else {
      in[x] = 1;
      ++sum;
      tackle(a[x], 1);
      ans += cal(a[x]);
    }
    cout << ans << "\n";
  }
}
