#include <bits/stdc++.h>
using namespace std;
const int MAXP = 500000;
vector<int> prime;
vector<int> a, q;
vector<int> cnt;
void MakePrime() {
  vector<bool> is_prime(MAXP + 1, true);
  is_prime[0] = is_prime[1] = false;
  prime.reserve(MAXP + 10);
  for (int i = 2; i * i <= MAXP; i++) {
    if (is_prime[i]) {
      prime.push_back(i);
      for (int j = 2; i * j <= MAXP; j++) is_prime[i * j] = false;
    }
  }
  for (int i = sqrt(MAXP) + 1; i <= MAXP; i++)
    if (is_prime[i]) prime.push_back(i);
}
vector<int> Factorize(int x) {
  vector<int> factors;
  factors.reserve(10);
  for (int i = 0; prime[i] * prime[i] <= x; i++) {
    if (x % prime[i] == 0) {
      factors.push_back(prime[i]);
      do {
        x /= prime[i];
      } while (x % prime[i] == 0);
    }
  }
  if (x > 1) factors.push_back(x);
  return factors;
}
int lowbit(int x) { return -x & x; }
int NextState(int x) {
  int lb = lowbit(x);
  int high = x + lb;
  int lower = ((x ^ (x + lb)) / lb) >> 2;
  return high | lower;
}
void ReadIn() {
  int n, m;
  scanf("%d%d", &n, &m);
  a.resize(n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  q.resize(m);
  for (int i = 0; i < m; i++) scanf("%d", &q[i]);
}
void Solve() {
  MakePrime();
  cnt.resize(MAXP + 1, 0);
  vector<bool> exist(a.size(), false);
  long long ans = 0;
  for (int t = 0; t < q.size(); t++) {
    q[t]--;
    vector<int> factors = Factorize(a[q[t]]);
    if (!exist[q[t]])
      ans += cnt[1]++;
    else
      ans -= --cnt[1];
    for (int bit = 1, sign = -1, max_state = (1 << factors.size());
         bit <= factors.size(); bit++, sign *= -1) {
      for (int s = (1 << bit) - 1; s < max_state; s = NextState(s)) {
        int divisor = 1;
        for (int b = 0; b < factors.size(); b++)
          if ((1 << b) & s) divisor *= factors[b];
        if (!exist[q[t]])
          ans += sign * cnt[divisor]++;
        else
          ans -= sign * --cnt[divisor];
      }
    }
    exist[q[t]] = !exist[q[t]];
    printf("%I64d\n", ans);
  }
}
int main() {
  ReadIn();
  Solve();
  return 0;
}
