#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool MinPlace(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool MaxPlace(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
vector<long long> prime;
long long spf[1000005];
bool is[1000005];
void sieve(long long n) {
  bool is[n + 1];
  memset(is, true, sizeof(is));
  for (long long p = 2; p * p <= n; p++) {
    if (is[p] == true) {
      for (long long i = p * 2; i <= n; i += p) is[i] = false;
    }
  }
  for (long long p = 2; p <= n; p++) {
    if (is[p]) {
      prime.push_back(p);
    }
  }
}
void logNfactorization(long long n) {
  spf[1] = 1;
  for (long long i = 2; i < n; i++) spf[i] = i;
  for (long long i = 4; i < n; i += 2) spf[i] = 2;
  for (long long i = 3; i * i < n; i++) {
    if (spf[i] == i) {
      for (long long j = i * i; j < n; j += i)
        if (spf[j] == j) spf[j] = i;
    }
  }
}
vector<long long> primefactor[500500];
long long a[500500], b[500500], freq[500500], multi[500500];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  sieve(1000000);
  logNfactorization(1000000);
  long long n, q;
  set<long long> s1;
  cin >> n >> q;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    long long x = a[i];
    b[i] = 1;
    while (x > 1) {
      long long sp = spf[x];
      b[i] *= sp;
      while (x % sp == 0) {
        x /= sp;
      }
    }
  }
  for (long long i = 1; i <= 500000; i++) {
    long long x = i;
    while (x > 1) {
      long long sp = spf[x];
      primefactor[i].push_back(sp);
      while (x % sp == 0) {
        x /= sp;
      }
    }
  }
  long long baseans = 0;
  set<long long> values;
  while (q--) {
    long long x, idx;
    cin >> idx;
    idx--;
    x = b[idx];
    if (s1.find(idx) == s1.end()) {
      long long len = primefactor[x].size();
      for (long long mask = 0; mask < (1 << len); mask++) {
        long long num = 1;
        for (long long j = 0; j < len; j++) {
          if (mask & (1 << j)) num *= (primefactor[x][j]);
        }
        long long currans = ((multi[num] * (multi[num] - 1)) / 2) *
                            ((primefactor[num].size() % 2) ? -1 : 1);
        multi[num]++;
        long long newans = ((multi[num] * (multi[num] - 1)) / 2) *
                           ((primefactor[num].size() % 2) ? -1 : 1);
        baseans += newans - currans;
      }
      s1.insert(idx);
    } else {
      long long len = primefactor[x].size();
      for (long long mask = 0; mask < (1 << len); mask++) {
        long long num = 1;
        for (long long j = 0; j < len; j++) {
          if (mask & (1 << j)) num *= (primefactor[x][j]);
        }
        long long currans = ((multi[num] * (multi[num] - 1)) / 2) *
                            ((primefactor[num].size() % 2) ? -1 : 1);
        multi[num]--;
        long long newans = ((multi[num] * (multi[num] - 1)) / 2) *
                           ((primefactor[num].size() % 2) ? -1 : 1);
        baseans += newans - currans;
      }
      s1.erase(idx);
    }
    cout << baseans << endl;
  }
}
