#include <bits/stdc++.h>
using namespace std;
const int maxv = 500010;
const int maxn = 200010;
int v[maxn];
bool isOnShelf[maxn];
vector<int> p[maxv];
int n, q;
int sets[maxv];
int preCount;
long long pre;
void Init() {
  for (int i = 2; i < maxv; i++) {
    if (p[i].empty()) {
      for (int j = i; j < maxv; j += i) {
        p[j].push_back(i);
      }
    }
  }
}
void removeBeer(int x) {
  int len = p[x].size();
  int tot = (1 << len) - 1;
  int tans = 0;
  for (int i = 1; i <= tot; i++) {
    int cur = 1, nums = 0;
    for (int j = 0; j < len; j++) {
      if ((1 << j) & i) {
        cur *= p[x][j], nums++;
      }
    }
    sets[cur]--;
    if (nums % 2)
      tans += sets[cur];
    else
      tans -= sets[cur];
  }
  preCount--;
  pre -= (preCount - tans);
}
void addBeer(int x) {
  int len = p[x].size();
  int tot = (1 << len) - 1;
  int tans = 0;
  for (int i = 1; i <= tot; i++) {
    int cur = 1, nums = 0;
    for (int j = 0; j < len; j++) {
      if ((1 << j) & i) {
        cur *= p[x][j], nums++;
      }
    }
    if (nums % 2)
      tans += sets[cur];
    else
      tans -= sets[cur];
    sets[cur]++;
  }
  pre += (preCount - tans);
  preCount++;
}
int main() {
  Init();
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) scanf("%d", v + i);
  while (q--) {
    int index;
    scanf("%d", &index);
    if (isOnShelf[index]) {
      removeBeer(v[index]);
      printf("%I64d\n", pre);
      isOnShelf[index] = false;
    } else {
      addBeer(v[index]);
      printf("%I64d\n", pre);
      isOnShelf[index] = true;
    }
  }
  return 0;
}
