#include <bits/stdc++.h>
inline int rint() {
  int x = 0, f = 1;
  char s = getchar();
  for (; s < '0' || '9' < s; s = getchar()) f = s == '-' ? -f : f;
  for (; '0' <= s && s <= '9'; s = getchar()) x = x * 10 + (s ^ '0');
  return x * f;
}
template <typename Tp>
inline void wint(Tp x) {
  if (x < 0) putchar('-'), x = ~x + 1;
  if (9 < x) wint(x / 10);
  putchar(x % 10 ^ '0');
}
const int MAXN = 2e5, MAXM = 5e5;
int n, m, q, a[MAXN + 5], f[MAXM + 5];
int pn, pr[MAXM + 5], mu[MAXM + 5];
bool vis[MAXM + 5], appr[MAXN + 5];
inline void sieve(const int n) {
  mu[1] = 1;
  for (int i = 2; i <= n; ++i) {
    if (!vis[i]) mu[pr[++pn] = i] = -1;
    for (int j = 1, t; j <= pn && (t = i * pr[j]) <= n; ++j) {
      vis[t] = true;
      if (!(i % pr[j])) break;
      mu[t] = -mu[i];
    }
  }
}
inline void contr(const int x, const int k) {
  for (int i = 1, sx = sqrt(x); i <= sx; ++i) {
    if (x % i) continue;
    f[i] += k;
    if (i != sx || i * i != x) f[x / i] += k;
  }
}
inline long long calc(const int x) {
  long long ret = 0;
  for (int i = 1, sx = sqrt(x); i <= sx; ++i) {
    if (x % i) continue;
    ret += mu[i] * f[i];
    if (i != sx || i * i != x) ret += mu[x / i] * f[x / i];
  }
  return ret;
}
int main() {
  n = rint(), q = rint();
  for (int i = 1; i <= n; ++i) {
    a[i] = rint();
    if (m < a[i]) m = a[i];
  }
  sieve(m);
  long long ans = 0;
  for (int x; q--;) {
    x = rint();
    if (appr[x]) contr(a[x], -1);
    ans += appr[x] ? -calc(a[x]) : calc(a[x]);
    if (!appr[x]) contr(a[x], 1);
    appr[x] ^= 1;
    wint(ans), putchar('\n');
  }
  return 0;
}
