#include <bits/stdc++.h>
int n, Q;
namespace math {
const int SIZE = 500001;
int prime[SIZE], mu[SIZE];
int tot;
bool isnprime[SIZE];
void sieve() {
  isnprime[1] = true;
  mu[1] = 1;
  for (int i = 2; i < SIZE; i++) {
    if (!isnprime[i]) {
      prime[++tot] = i;
      mu[i] = -1;
    }
    for (int j = 1; i * prime[j] < SIZE; j++) {
      isnprime[i * prime[j]] = true;
      if (!(i % prime[j])) {
        mu[i * prime[j]] = 0;
        break;
      }
      mu[i * prime[j]] = -mu[i];
    }
  }
}
}  // namespace math
int B[200001];
int T[500001];
bool in[200001];
long long Ans;
std::vector<int> Div[200001];
int main() {
  math::sieve();
  scanf("%d%d", &n, &Q);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &B[i]);
    for (int j = 1; j * j <= B[i]; j++) {
      if (!(B[i] % j)) Div[i].push_back(j), Div[i].push_back(B[i] / j);
      if (j * j == B[i]) Div[i].pop_back();
    }
  }
  for (int i = 1, O; i <= Q; i++) {
    scanf("%d", &O);
    if (in[O]) {
      for (std::vector<int>::iterator it = Div[O].begin(); it != Div[O].end();
           ++it)
        T[*it]--;
      for (std::vector<int>::iterator it = Div[O].begin(); it != Div[O].end();
           ++it)
        Ans -= math::mu[*it] * T[*it];
      in[O] = false;
    } else {
      for (std::vector<int>::iterator it = Div[O].begin(); it != Div[O].end();
           ++it)
        Ans += math::mu[*it] * T[*it];
      for (std::vector<int>::iterator it = Div[O].begin(); it != Div[O].end();
           ++it)
        T[*it]++;
      in[O] = true;
    }
    printf("%lld\n", Ans);
  }
}
