#include <bits/stdc++.h>
using namespace std;
const int maxv = 5e5 + 400;
vector<int> G[maxv];
vector<int> pri;
bool p[maxv];
set<int> beer;
int f[maxv], c[maxv], a[maxv];
int n, q;
void init() {
  for (int i = 2; i < maxv; i++) {
    if (!p[i]) pri.push_back(i);
    for (int j = 0; j < pri.size() && i * pri[j] < maxv; j++) {
      p[i * pri[j]] = 1;
      if (i % pri[j] == 0) break;
    }
  }
}
void getp() {
  for (int i = 0; i < n; i++) {
    int x = a[i];
    int h = 0;
    while (x > 1 && pri[h] * pri[h] <= x) {
      if (x % pri[h] == 0) {
        G[i].push_back(pri[h]);
        while (x > 1 && x % pri[h] == 0) x /= pri[h];
      }
      h++;
    }
    if (x != 1) G[i].push_back(x);
  }
}
void read() {
  cin >> n >> q;
  for (int i = 0; i < n; i++) scanf("%d", a + i);
}
long long ans = 0;
int top = 0;
void dfs(int t, int x, int cont, int flag, int val) {
  if (t >= (int)G[x].size()) {
    if (cont == 0) return;
    ans += f[val] * flag;
    c[top++] = val;
    return;
  }
  dfs(t + 1, x, cont, flag, val);
  dfs(t + 1, x, cont + 1, flag * -1, val * G[x][t]);
}
void solve() {
  int x;
  while (q--) {
    scanf("%d", &x);
    x--;
    if (a[x] == 1) {
      if (beer.find(x) != beer.end()) {
        beer.erase(x);
        ans -= beer.size();
      } else {
        ans += beer.size();
        beer.insert(x);
      }
    } else {
      if (beer.find(x) != beer.end()) {
        beer.erase(x);
        ans -= beer.size();
        top = 0;
        dfs(0, x, 0, -1, 1);
        ans--;
        beer.erase(x);
        for (int i = 0; i < top; i++) f[c[i]]--;
      } else {
        top = 0;
        ans += beer.size();
        dfs(0, x, 0, 1, 1);
        beer.insert(x);
        for (int i = 0; i < top; i++) f[c[i]]++;
      }
    }
    printf("%lld\n", ans);
  }
}
int main() {
  init();
  read();
  getp();
  solve();
  return 0;
}
