#include <bits/stdc++.h>
using namespace std;
const int maxn = 200001;
int cnt[maxn * 3];
bool in[maxn];
vector<int> p[maxn];
int n, q, x;
long long ans;
int a[maxn], sz;
int calc(int cur) {
  int ans = 0;
  for (int i = 1; i < (1 << p[cur].size()); i++) {
    int num = 0, s = 1;
    for (int j = 0; j < p[cur].size(); j++)
      if (i & (1 << j)) num++, s *= p[cur][j];
    if (num % 2)
      ans += cnt[s];
    else
      ans -= cnt[s];
  }
  return ans;
}
void add(int cur, int tp) {
  for (int i = 0; i < (1 << p[cur].size()); i++) {
    int s = 1;
    for (int j = 0; j < p[cur].size(); j++)
      if (i & (1 << j)) s *= p[cur][j];
    cnt[s] += tp;
  }
  return;
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    int temp = a[i];
    p[i].clear();
    for (int j = 2; j * j <= temp; j++) {
      if (temp % j == 0) p[i].push_back(j);
      while (temp % j == 0) temp /= j;
    }
    if (temp != 1) p[i].push_back(temp);
    in[i] = false;
  }
  sz = 0;
  for (int _ = 1; _ <= q; _++) {
    scanf("%d", &x);
    if (!in[x]) {
      ans += (long long)(sz - calc(x));
      sz++;
      add(x, 1);
      in[x] = true;
    } else {
      add(x, -1);
      sz--;
      ans -= (long long)(sz - calc(x));
      in[x] = false;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
