#include <bits/stdc++.h>
using namespace std;
int prime[500010], flag[500010], cnt, c[500010];
vector<int> zjk[500010];
void make() {
  for (int i = 2; i <= 500000; i++) {
    if (!flag[i]) prime[++cnt] = i;
    for (int j = 1; j <= cnt && i * prime[j] <= 500000; j++) {
      flag[i * prime[j]] = 1;
      if (i % prime[j] == 0) break;
    }
  }
  for (int i = 2; i <= 500000; i++) {
    if (!flag[i])
      zjk[i].push_back(i);
    else {
      int k = i;
      for (int j = 1; j <= cnt && prime[j] * prime[j] <= k; j++)
        if (k % prime[j] == 0) {
          zjk[i].push_back(prime[j]);
          while (k % prime[j] == 0) k /= prime[j];
        }
      if (k != 1) zjk[i].push_back(k);
    }
  }
}
int t = 0;
long long query(int x) {
  int k = zjk[x].size();
  long long ans = t;
  for (int s = 1; s < (1 << k); s++) {
    int del = 1, res = 1;
    for (int j = 1; j <= k; j++)
      if (s & (1 << (j - 1))) del = -del, res *= zjk[x][j - 1];
    ans += del * (long long)c[res];
  }
  return ans;
}
void add(int x, int d) {
  int k = zjk[x].size();
  t += d;
  for (int s = 1; s < (1 << k); s++) {
    int res = 1;
    for (int j = 1; j <= k; j++)
      if (s & (1 << (j - 1))) res *= zjk[x][j - 1];
    c[res] += d;
  }
}
int num[500010], book[500010];
int main() {
  make();
  int n, q, a;
  long long hh = 0;
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) scanf("%d", &num[i]);
  for (int i = 1; i <= q; i++) {
    scanf("%d", &a);
    if (book[a])
      add(num[a], -1), hh -= query(num[a]);
    else
      hh += query(num[a]), add(num[a], 1);
    book[a] = 1 - book[a];
    printf("%lld\n", hh);
  }
}
