#include <bits/stdc++.h>
using namespace std;
vector<int> p[500005];
int n, q, a[200005], b[500005], c[105], s[200005];
long long ans;
void add(int x, int y) {
  int t;
  for (t = 0; t < (1 << p[x].size()); t++) {
    if (t)
      c[t] = c[t ^ (t & (-t))] * p[x][__builtin_ctz(t)];
    else
      c[t] = 1;
    if (y < 0) b[c[t]]--;
    if (__builtin_popcount(t) & 1)
      ans -= b[c[t]] * y;
    else
      ans += b[c[t]] * y;
    if (y > 0) b[c[t]]++;
  }
}
int main() {
  int i, j;
  for (i = 2; i <= 500000; i++) {
    if (p[i].empty()) {
      for (j = i; j <= 500000; j += i) p[j].push_back(i);
    }
  }
  scanf("%d%d", &n, &q);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    s[i] = 1;
  }
  ans = 0;
  while (q--) {
    int x;
    scanf("%d", &x);
    add(a[x - 1], s[x - 1]);
    s[x - 1] *= -1;
    printf("%I64d\n", ans);
  }
  return 0;
}
