#include <bits/stdc++.h>
using namespace std;
const double EPS = -1e8;
const double Pi = acos(-1);
bool inline equ(double a, double b) { return fabs(a - b) < EPS; }
const int MAXN = 500010;
vector<int> pfac[MAXN];
void init() {
  for (int i = (2); i <= (MAXN - 1); i++) {
    if ((int)(pfac[i]).size()) continue;
    for (int j = i; j < MAXN; j += i) pfac[j].push_back(i);
  }
}
int n, q, in[MAXN];
bool live[MAXN];
int cnt[MAXN];
tuple<int, int> eval(int comb, int x) {
  int par = 1, res = 1;
  for (int i = (0); i <= ((int)(pfac[x]).size() - 1); i++)
    if (comb & (1 << i)) {
      par *= -1;
      res *= pfac[x][i];
    }
  return tuple<int, int>(par, res);
}
int main() {
  init();
  scanf("%d%d", &n, &q);
  for (int i = (1); i <= (n); i++) scanf("%d", in + i);
  long long ans = 0ll;
  while (q--) {
    int id;
    scanf("%d", &id);
    long long res = 0ll;
    if (live[id]) {
      live[id] = 0;
      for (int comb = 0; comb < (1 << (int)(pfac[in[id]]).size()); comb++) {
        int par, x;
        tie(par, x) = eval(comb, in[id]);
        cnt[x]--;
        res += par * cnt[x];
      }
      ans -= res;
    } else {
      live[id] = 1;
      for (int comb = 0; comb < (1 << (int)(pfac[in[id]]).size()); comb++) {
        int par, x;
        tie(par, x) = eval(comb, in[id]);
        res += par * cnt[x];
        cnt[x]++;
      }
      ans += res;
    }
    printf("%I64d\n", ans);
  }
}
