#include <bits/stdc++.h>
using namespace std;
const int maxn = 500500;
bool x[maxn];
int p[maxn], num[maxn], tmp[110];
int main() {
  int n, q;
  long long ans = 0;
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; i++) scanf("%d", num + i + 1);
  for (int u = 0; u < q; u++) {
    int t, k, cnt = 0;
    scanf("%d", &t);
    k = num[t];
    if (x[t]) {
      for (int i = 2; i * i <= k; i++)
        if (k % i == 0) {
          tmp[cnt++] = i;
          while (k % i == 0) k /= i;
        }
      if (k != 1) tmp[cnt++] = k;
      for (int i = 0; i < (1 << cnt); i++) {
        long long cur = 0;
        int add = 0, mult = 1;
        for (int j = 0; j < cnt; j++)
          if (i & (1 << j)) mult *= tmp[j], add++;
        p[mult]--;
        cur = p[mult];
        if (add & 1)
          ans += cur;
        else
          ans -= cur;
      }
      x[t] = 0;
    } else {
      for (int i = 2; i * i <= k; i++)
        if (k % i == 0) {
          tmp[cnt++] = i;
          while (k % i == 0) k /= i;
        }
      if (k != 1) tmp[cnt++] = k;
      for (int i = 0; i < (1 << cnt); i++) {
        long long cur = 0;
        int add = 0, mult = 1;
        for (int j = 0; j < cnt; j++)
          if (i & (1 << j)) mult *= tmp[j], add++;
        cur = p[mult];
        p[mult]++;
        if (add & 1)
          ans -= cur;
        else
          ans += cur;
      }
      x[t] = 1;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
