#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int MX = 500000;
vector<int> v;
int sieve[MX + 5];
int cnt[MX + 5];
int arr[N];
long long ans;
int n, q;
int get(int pos, int mul, int sign) {
  if (pos == v.size()) {
    return mul == 1 ? 0 : sign * cnt[mul];
  }
  int res = 0;
  res += get(pos + 1, mul, sign);
  res += get(pos + 1, mul * v[pos], sign * -1);
  return res;
}
void update(int pos, int mul, int sign) {
  if (pos == v.size())
    cnt[mul] += sign;
  else {
    update(pos + 1, mul, sign);
    update(pos + 1, mul * v[pos], sign);
  }
}
void check() {
  bool ok = 1;
  for (int i = 1; i < v.size(); i++) ok &= (v[i] < v[i - 1]);
  printf("%s\n", ok ? "OK" : "SH");
}
long long query(int x) {
  v.clear();
  while (x != 1) {
    int div = sieve[x];
    while (sieve[x] == div) x /= div;
    v.push_back(div);
  }
  return get(0, 1, -1);
}
void upd(int x, int sign) {
  v.clear();
  while (x != 1) {
    int div = sieve[x];
    while (sieve[x] == div) x /= div;
    v.push_back(div);
  }
  update(0, 1, sign);
}
void sieving() {
  for (int i = 2; i <= MX; i++)
    if (sieve[i] == 0)
      for (int j = i; j <= MX; j += i) sieve[j] = i;
}
void init() {
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
    arr[i] = -arr[i];
  }
}
void solve() {
  int on = 0;
  for (int i = 1; i <= q; i++) {
    int x;
    scanf("%d", &x);
    if (arr[x] > 0) {
      ans -= (-query(arr[x]) + on);
      if (arr[x] == 1) ans++;
      upd(arr[x], -1);
      on--;
    } else {
      ans += (-query(-arr[x]) + on);
      upd(-arr[x], 1);
      on++;
    }
    arr[x] = -arr[x];
    printf("%I64d\n", ans);
  }
}
int main() {
  sieving();
  init();
  solve();
  return 0;
}
