#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 1e18;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const int maxmat = 10;
const unsigned long long BASE = 133333331;
inline void RI(int &x) {
  char c;
  while ((c = getchar()) < '0' || c > '9')
    ;
  x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0';
}
inline long long bits(long long x) { return !x ? x : bits(x - (x & -x)) + 1; }
const int maxn = 5e5 + 5;
std::vector<int> prime;
bool mark[maxn];
int u[maxn];
int N, M;
int a[maxn];
int cnt[maxn];
bool used[maxn];
long long ans;
void init() {
  u[1] = 1;
  memset(mark, false, sizeof(mark));
  for (int i = 2; i < 5e5; i++) {
    if (!mark[i]) {
      prime.push_back(i);
      u[i] = -1;
    }
    for (unsigned j = 0; j < prime.size(); j++) {
      int tmp = i * prime[j];
      if (tmp > 5e5) break;
      mark[tmp] = true;
      if (i % prime[j] == 0) {
        u[tmp] = 0;
        break;
      } else
        u[tmp] = -u[i];
    }
  }
}
long long C(int m, int n) {
  if (n > m) return 0;
  long long res = 1;
  for (int i = 0; i < n; i++) {
    res *= (m - i);
    res /= (i + 1);
  }
  return res;
}
void get_c(int x, int on) {
  for (int i = 1; (long long)i * i <= x; i++)
    if (x % i == 0) {
      ans = ans - (long long)u[i] * C(cnt[i], 2) +
            (long long)u[i] * C(cnt[i] + on, 2);
      cnt[i] += on;
      if ((long long)i * i != x) {
        ans = ans - (long long)u[x / i] * C(cnt[x / i], 2) +
              (long long)u[x / i] * C(cnt[x / i] + on, 2);
        cnt[x / i] += on;
      }
    }
}
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  init();
  cin >> N >> M;
  memset(used, false, sizeof(used));
  for (int i = 1; i <= N; i++) cin >> a[i];
  ans = 0;
  for (int i = 0; i < M; i++) {
    int x;
    cin >> x;
    get_c(a[x], used[x] ? -1 : 1);
    used[x] ^= 1;
    cout << ans << endl;
  }
  return 0;
}
