#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 1e18;
template <typename T>
void read(T &x) {
  x = 0;
  int s = 1, c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') s = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
  x *= s;
}
template <typename T>
void write(T x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
void writeln(T x) {
  write(x);
  puts("");
}
const int maxn = 2e5 + 5, maxa = 5e5 + 5;
int n, q, a[maxn], maxx;
int primes[maxa], tot, vis[maxa], mu[maxa];
vector<int> fac[maxa];
long long ans;
int g[maxa];
bool mark[maxn];
void Pre() {
  mu[1] = 1;
  for (int i = 2; i <= maxx; i++) {
    if (!vis[i]) {
      primes[++tot] = i;
      mu[i] = -1;
    }
    for (int j = 1; j <= tot && (long long)primes[j] * i <= maxx; j++) {
      vis[primes[j] * i] = 1;
      if (i % primes[j] == 0) break;
      mu[primes[j] * i] = -mu[i];
    }
  }
  for (int i = 1; i <= maxx; i++)
    for (int j = 1; (long long)j * i <= maxx; j++) fac[j * i].push_back(i);
}
int main() {
  read(n), read(q);
  for (int i = 1; i <= n; i++) read(a[i]), maxx = max(maxx, a[i]);
  Pre();
  for (int i; q; q--) {
    read(i);
    if (!mark[i]) {
      mark[i] = 1;
      for (int d : fac[a[i]]) {
        ans += mu[d] * g[d];
        g[d]++;
      }
    } else {
      mark[i] = 0;
      for (int d : fac[a[i]]) {
        g[d]--;
        ans -= mu[d] * g[d];
      }
    }
    writeln(ans);
  }
  return 0;
}
