#include <bits/stdc++.h>
using namespace std;
char BUFFER[100000 + 5];
bool readn(int &n) { return scanf("%d", &n) == 1; }
bool readl(long long &n) { return scanf("%I64d", &n) == 1; }
bool readd(double &n) { return scanf("%lf", &n) == 1; }
bool reads(string &s) {
  s = "";
  int n = scanf("%s", BUFFER);
  if (n == 1) s = BUFFER;
  return n == 1;
}
bool readln(string &s) {
  char *valid = gets(BUFFER);
  if (valid) s = BUFFER;
  return ((bool)valid);
}
const int maxn = 5e5 + 10;
int m[maxn], a[maxn / 2], f[20];
bool p[maxn], vis[maxn];
int factorize(int n) {
  int i, cnt = 0;
  for (i = 2; i * i <= n; i++)
    if (n % i == 0) {
      f[cnt++] = i;
      while (n % i == 0) n /= i;
    }
  if (n > 1) f[cnt++] = n;
  return cnt;
}
long long nop = 0, total = 0, cnt[maxn];
void init() {
  int i, j;
  memset((cnt), (0), sizeof(cnt));
  for (i = 0; i < maxn; ++i) {
    m[i] = -1;
    p[i] = true;
  }
  memset((vis), (false), sizeof(vis));
  for (i = 2; i < maxn; ++i)
    if (p[i])
      for (j = i; j < maxn; j += i) {
        p[j] = false;
        m[j] = -m[j];
      }
}
long long calc(int x) {
  int i, j, fn = factorize(a[x]), mult = 1, su;
  if (vis[x]) {
    mult = -1;
    total--;
  } else
    total++;
  vis[x] = !vis[x];
  for (i = 1; i < (1 << (fn)); ++i) {
    su = 1;
    for (j = 0; j < fn; ++j)
      if ((((i) & (1 << (j))) != 0)) su *= f[j];
    if (mult == 1)
      nop += (m[su] * cnt[su]);
    else
      nop -= (m[su] * (cnt[su] - 1));
    cnt[su] += mult;
  }
  long long ans = total * (total - 1) / 2;
  ans -= nop;
  return ans;
}
int main() {
  init();
  int i, n, q, x;
  cin >> n >> q;
  for (i = 0; i < n; ++i) cin >> a[i];
  for (i = 0; i < q; ++i) {
    cin >> x;
    cout << calc(x - 1) << endl;
  }
  return 0;
}
