#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5;
int prime[5 * MAXN + 100];
int p[5 * MAXN + 100][100];
int vis[5 * MAXN + 100];
int vis_times[5 * MAXN + 100];
int val[MAXN * 5 + 100];
void start() {
  for (int i = 2; i <= 5 * MAXN; i++) {
    if (!prime[i]) prime[++prime[0]] = i;
    for (int j = 1; j <= prime[0] && prime[j] * i <= 5 * MAXN; j++) {
      prime[prime[j] * i] = 1;
      if (i % prime[j] == 0) break;
    }
  }
  for (int i = 1; i <= prime[0]; i++) {
    int k = prime[i];
    for (int j = k; j <= 5 * MAXN; j += k) p[j][++p[j][0]] = k;
  }
}
int solve(int n) {
  int len = p[n][0], ret = 0;
  for (int i = 1; i <= (1 << len) - 1; i++) {
    int tmp = 1;
    int cnt = 0;
    for (int j = 0; j <= len; j++)
      if (i & (1 << j)) {
        tmp *= p[n][j + 1];
        cnt++;
      }
    if (cnt & 1)
      ret += vis_times[tmp];
    else
      ret -= vis_times[tmp];
  }
  if (ret) ret--;
  return ret;
}
void cnt(int n, int val) {
  for (int i = 1; i * i <= n; i++)
    if (n % i == 0) {
      vis_times[i] += val;
      if (n / i != i) vis_times[n / i] += val;
    }
}
int main() {
  start();
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%d", val + i);
  long long ret = 0, ans = 0;
  for (int i = 1; i <= m; i++) {
    int tmp;
    scanf("%d", &tmp);
    if (vis[tmp]) {
      ans -= ret - 1 - solve(val[tmp]);
      vis[tmp] = 0;
      cnt(val[tmp], -1);
      ret--;
    } else {
      vis[tmp] = 1;
      cnt(val[tmp], 1);
      ret++;
      ans += ret - 1 - solve(val[tmp]);
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
