#include <bits/stdc++.h>
using namespace std;
int B[500005];
vector<int> v[200005];
void Init() {
  B[1] = 1;
  for (int i = 1; i < 500005; i++) {
    for (int j = i + i; j < 500005; j += i) B[j] -= B[i];
  }
}
int n, q;
int C[500005];
bool mark[200005];
int main() {
  Init();
  scanf("%d %d", &n, &q);
  for (int i = 1, x; i <= n; i++) {
    scanf("%d", &x);
    for (int j = 1; j * j <= x; j++) {
      if (x % j == 0) {
        if (B[j]) v[i].push_back(j);
        if (j * j == x) continue;
        if (B[x / j]) v[i].push_back(x / j);
      }
    }
  }
  long long res = 0;
  for (int i = 1, x; i <= q; i++) {
    scanf("%d", &x);
    mark[x] ^= true;
    for (int j = 0; j < v[x].size(); j++) {
      int now = v[x][j];
      res -= 1ll * C[now] * (C[now] - 1) * B[now] / 2;
      if (mark[x] == true)
        C[now]++;
      else
        C[now]--;
      res += 1ll * C[now] * (C[now] - 1) * B[now] / 2;
    }
    cout << res << endl;
  }
  return 0;
}
