#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int lp[N + 1], pr[42000], c = 0;
int n, q, a[200005], D[N];
bitset<N> used;
vector<int> cache[N];
void uni(vector<int>& v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
int main() {
  for (int i = 2; i <= N; ++i) {
    if (lp[i] == 0) lp[i] = i, pr[c++] = i;
    for (int j = 0; j < c && pr[j] <= lp[i] && i * pr[j] <= N; ++j)
      lp[i * pr[j]] = pr[j];
  }
  scanf("%d %d", &n, &q);
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  long long ans = 0;
  while (q--) {
    int y;
    scanf("%d", &y);
    y -= 1;
    int x = a[y];
    if (cache[x].empty()) {
      for (int z = x; z > 1; z /= lp[z]) cache[x].push_back(lp[z]);
      uni(cache[x]);
    }
    for (int i = 0; i < (1 << cache[x].size()); ++i) {
      int z = 1, popcnt = 0;
      for (int j = 0, k = i; k > 0; j++, k /= 2)
        if (k & 1) z *= cache[x][j], ++popcnt;
      long long moeb = popcnt % 2 == 1 ? -1 : 1;
      ans -= moeb * D[z] * (D[z] - 1) / 2;
      D[z] += !used[y] ? 1 : -1;
      ans += moeb * D[z] * (D[z] - 1) / 2;
    }
    printf("%lld\n", ans);
    used.flip(y);
  }
}
