#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T gcd(T a, T b) {
  return (b) == 0 ? (a) : gcd((b), ((a) % (b)));
}
template <class T>
inline T lcm(T a, T b) {
  return ((a) / gcd((a), (b)) * (b));
}
template <class T>
inline T BigMod(T Base, T power, T M = 1000000007) {
  if (power == 0) return 1;
  if (power & 1)
    return ((Base % M) * (BigMod(Base, power - 1, M) % M)) % M;
  else {
    T y = BigMod(Base, power / 2, M) % M;
    return (y * y) % M;
  }
}
template <class T>
inline T ModInv(T A, T M = 1000000007) {
  return BigMod(A, M - 2, M);
}
int fx[] = {-1, +0, +1, +0, +1, +1, -1, -1, +0};
int fy[] = {+0, -1, +0, +1, +1, -1, +1, -1, +0};
int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int arr[500005], prime[500005], p, e[500005];
vector<int> v[500005];
long long ans;
int exist[500005];
long long res[500005], pes[500005];
int len, jk;
void sieve(int n) {
  double z = sqrt(n);
  for (long long i = 3; i <= z; i += 2) {
    if (!arr[i])
      for (long long j = i * i; j <= n; j += i + i) {
        arr[j] = 1;
      }
  }
  prime[p++] = 2;
  for (int i = 3; i <= n; i += 2)
    if (!arr[i]) prime[p++] = i;
}
void pre() {
  for (int i = 0; i < p; i++) {
    for (int j = prime[i]; j < 500005; j += prime[i]) {
      v[j].push_back(prime[i]);
    }
  }
  e[1] = 1;
  for (int i = 2; i < 500005; i++) {
    if ((int)v[i].size() & 1)
      e[i] = -1;
    else
      e[i] = 1;
  }
  for (long long i = 2; i < 500005; i++) {
    long long x = i * i;
    for (long long j = x; j < 500005; j += x) e[j] = 0;
  }
}
void Div(int pos, int pk, long long rr = 1) {
  if (pos == len) {
    long long z = res[rr];
    z = (z * (z - 1)) / 2;
    ans -= (e[rr] * z);
    res[rr] += pk;
    z = res[rr];
    z = (z * (z - 1)) / 2;
    ans += (e[rr] * z);
    return;
  }
  Div(pos + 1, pk, rr * v[jk][pos]);
  Div(pos + 1, pk, rr);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  sieve(500005);
  pre();
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  for (int i = 1; i <= q; i++) {
    int a;
    cin >> a;
    len = v[arr[a]].size();
    jk = arr[a];
    if (exist[a]) {
      Div(0, -1);
    } else {
      Div(0, 1);
    }
    exist[a] = 1 - exist[a];
    cout << ans << endl;
  }
  return 0;
}
