#include <bits/stdc++.h>
using namespace std;
int ara[200005], data[500005], total_glass, ans;
long long now_ans;
int is_it[200005];
vector<int> all[500005];
void func(vector<int> &v, int now, int value, int total, int turn) {
  if (now == v.size()) {
    if (!total) return;
    if (!turn) data[value]--;
    if (total % 2)
      ans += data[value];
    else
      ans -= data[value];
    if (turn) data[value]++;
    return;
  }
  func(v, now + 1, value, total, turn);
  func(v, now + 1, value * v[now], total + 1, turn);
  return;
}
int main() {
  memset(is_it, 0, sizeof(is_it));
  memset(data, 0, sizeof(data));
  total_glass = now_ans = 0;
  int i, n, j, q;
  scanf("%d", &n);
  scanf("%d", &q);
  for (i = 0; i < n; i++) scanf("%d", &ara[i]);
  for (i = 2; i < 500005; i++) {
    if (all[i].size()) continue;
    for (j = 1; i * j < 500005; j++) all[i * j].push_back(i);
  }
  while (q--) {
    int x;
    scanf("%d", &x);
    x--;
    is_it[x] = !is_it[x];
    if (ara[x] == 1) {
      if (is_it[x]) {
        now_ans += total_glass;
        total_glass++;
      } else {
        total_glass--;
        now_ans -= total_glass;
      }
      printf("%I64d\n", now_ans);
      continue;
    }
    ans = 0;
    func(all[ara[x]], 0, 1, 0, is_it[x]);
    if (is_it[x]) {
      ans = total_glass - ans;
      total_glass++;
      now_ans += ans;
    } else {
      total_glass--;
      ans = total_glass - ans;
      now_ans -= ans;
    }
    printf("%I64d\n", now_ans);
  }
  return 0;
}
