#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 5e5 + 5;
bool vis[MAX_N];
vector<vector<int>> fac(MAX_N);
int pos[MAX_N];
int calc[MAX_N];
int cnt[MAX_N];
long long res = 0;
int main() {
  for (int i = 2; i < MAX_N - 1; i++) {
    if (!vis[i]) {
      for (int j = i; j < MAX_N - 1; j += i) {
        fac[j].push_back(i);
        vis[j] = true;
      }
    }
  }
  int n, q, x;
  scanf("%d %d", &n, &q);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  memset(pos, -1, sizeof(pos));
  for (int i = 0; i < q; ++i) {
    scanf("%d", &x), x--;
    if (pos[x] == -1)
      pos[x] = 1;
    else
      pos[x] = -1;
    for (int mask = 0; mask < (1 << fac[a[x]].size()); mask++) {
      if (!mask)
        calc[0] = 1;
      else
        calc[mask] = calc[mask & (mask - 1)] * fac[a[x]][__builtin_ctz(mask)];
      if (!(pos[x] + 1)) cnt[calc[mask]]--;
      if (__builtin_popcount(mask) % 2)
        res -= cnt[calc[mask]] * pos[x];
      else
        res += cnt[calc[mask]] * pos[x];
      if (pos[x] == 1) cnt[calc[mask]]++;
    }
    printf("%I64d\n", res);
  }
}
