#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
int a[maxn];
int est[maxn], vis[maxn];
int f[maxn];
int n, m, tot, L;
long long ans;
int prime[maxn], cnt;
int flag[maxn], mu[maxn];
void getpri() {
  for (int i = 2; i <= L; i++) {
    if (!flag[i]) prime[++cnt] = i, mu[i] = -1;
    for (int j = 1; i * prime[j] <= L && j <= cnt; j++) {
      flag[i * prime[j]] = 1;
      mu[i * prime[j]] = -mu[i];
      if (i % prime[j] == 0) {
        mu[i * prime[j]] = 0;
        break;
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), L = max(L, a[i]);
  getpri();
  memset(vis, -1, sizeof(vis));
  while (m--) {
    int i, x, H;
    scanf("%d", &i);
    x = a[i], H = sqrt(x) + 1;
    est[i] ^= 1;
    if (est[i])
      ans += tot++;
    else
      ans -= --tot;
    for (int j = 1; j <= H; j++)
      if (x % j == 0) {
        if (mu[j] && vis[j] != m) {
          vis[j] = m;
          if (est[i])
            ans += mu[j] * (f[j]++);
          else
            ans -= mu[j] * (--f[j]);
        }
        if (mu[x / j] && vis[x / j] != m) {
          vis[x / j] = m;
          if (est[i])
            ans += mu[x / j] * (f[x / j]++);
          else
            ans -= mu[x / j] * (--f[x / j]);
        }
      }
    printf("%I64d\n", ans);
  }
  return 0;
}
