#include <bits/stdc++.h>
using namespace std;
vector<bool> vis(5000005, true), open(2000005);
vector<int> primes, factors[2000005], freq(2000005);
void inex(int u) {
  for (int i = 1; i < (1 << (int)factors[u].size()); i++) {
    long long p = 1;
    for (int j = 0; j < (int)factors[u].size(); j++) {
      if ((i >> j) & 1) p *= factors[u][j];
    }
    if (open[u])
      freq[p]--;
    else
      freq[p]++;
  }
}
int get(int u) {
  int ret = 0;
  for (int i = 1; i < (1 << (int)factors[u].size()); i++) {
    long long p = 1;
    for (int j = 0; j < (int)factors[u].size(); j++) {
      if ((i >> j) & 1) p *= factors[u][j];
    }
    if (__builtin_popcount(i) & 1)
      ret += freq[p];
    else
      ret -= freq[p];
  }
  return ret;
}
int main() {
  vis[0] = vis[1] = false;
  for (int i = 2; i * i <= 500005; i++)
    if (vis[i])
      for (int j = i * i; j < 500005; j += i) vis[j] = false;
  for (int i = 0; i < 500005; i++)
    if (vis[i]) primes.push_back(i);
  int n, q, u, cursize = 0;
  long long ans = 0;
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; i++) {
    scanf("%d", &u);
    int idx = 0;
    while (u != 1) {
      if (vis[u]) {
        factors[i].push_back(u);
        u = 1;
      }
      if (u % primes[idx] == 0) factors[i].push_back(primes[idx]);
      while (u % primes[idx] == 0) u /= primes[idx];
      idx++;
    }
  }
  while (q--) {
    scanf("%d", &u);
    --u;
    if (open[u]) {
      cursize--;
      inex(u);
      ans -= cursize - get(u);
    } else {
      ans += cursize - get(u);
      inex(u);
      cursize++;
    }
    open[u] = !open[u];
    printf("%I64d\n", ans);
  }
  return 0;
}
