#include <bits/stdc++.h>
using namespace std;
int n, q;
int mob[500001], cnt[500001];
int noprime[500001], p[500001];
int star[500001], inSet[500001];
vector<int> mobNum[500001];
void Mobius() {
  memset(noprime, 0, sizeof(noprime));
  int pnum = 0;
  mob[1] = 1;
  for (int i = 2; i < 500001; i++) {
    if (!noprime[i]) {
      p[pnum++] = i;
      mob[i] = -1;
    }
    for (int j = 0; j < pnum && i * p[j] < 500001; j++) {
      noprime[i * p[j]] = true;
      if (i % p[j] == 0) {
        mob[i * p[j]] = 0;
        break;
      }
      mob[i * p[j]] = -mob[i];
    }
  }
}
void init() {
  for (int i = 0; i < 500001; i++) mobNum[i].clear();
  for (int i = 1; i < 500001; i++) {
    if (mob[i]) {
      for (int j = i; j < 500001; j += i) {
        mobNum[j].push_back(i);
      }
    }
  }
}
int main() {
  Mobius();
  init();
  while (scanf("%d%d", &n, &q) != EOF) {
    memset(cnt, 0, sizeof(cnt));
    memset(inSet, 0, sizeof(inSet));
    for (int i = 1; i <= n; i++) scanf("%d", &star[i]);
    long long ans = 0;
    while (q--) {
      int x;
      scanf("%d", &x);
      int siz = mobNum[star[x]].size();
      long long temp;
      if (inSet[x]) {
        temp = 0;
        for (int i = 0; i < siz; i++) {
          int v = mobNum[star[x]][i];
          cnt[v]--;
          temp += ((long long)mob[v] * (long long)cnt[v]);
        }
        ans -= temp;
        inSet[x] = 0;
      } else {
        temp = 0;
        for (int i = 0; i < siz; i++) {
          int v = mobNum[star[x]][i];
          temp += ((long long)mob[v] * (long long)cnt[v]);
          cnt[v]++;
        }
        ans += temp;
        inSet[x] = 1;
      }
      printf("%I64d\n", ans);
    }
  }
  return 0;
}
