#include <bits/stdc++.h>
using namespace std;
int fact[10], a[200010], vis[200010], num[500010];
long long ans;
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  int sum = 0, x;
  long long res = 0;
  for (int k = 1; k <= q; k++) {
    scanf("%d", &x);
    int y = a[x];
    int tot = 0, ans = 0;
    for (int i = 2; i * i <= y; i++) {
      if (y % i) continue;
      while (y % i == 0) y /= i;
      fact[tot++] = i;
    }
    if (y != 1) fact[tot++] = y;
    for (int i = 1; i < (1 << tot); i++) {
      int tmp = 1, cnt = 0;
      for (int j = 0; j < tot; j++) {
        if ((1 << j) & i) {
          tmp *= fact[j];
          cnt++;
        }
      }
      if (vis[x] == 0) {
        ans += 1LL * num[tmp] * ((cnt & 1) ? 1 : -1);
        num[tmp]++;
      } else {
        num[tmp]--;
        ans += 1LL * num[tmp] * ((cnt & 1) ? 1 : -1);
      }
    }
    if (vis[x] == 0) {
      res += 1LL * (sum - ans);
      cout << res << endl;
      sum++;
    } else {
      sum--;
      res -= 1LL * (sum - ans);
      cout << res << endl;
    }
    vis[x] ^= 1;
  }
  return 0;
}
