#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, M = 5e5 + 5;
long long ans, sz;
int arr[N], freq[M], numFreq[M], n;
bool on[N];
vector<int> primes[M];
void add(int ind, int cnt, int num, const vector<int> &v) {
  if (ind == v.size()) return;
  if (cnt % 2 == 0)
    ans += freq[num * v[ind]]++;
  else
    ans -= freq[num * v[ind]]++;
  add(ind + 1, cnt, num, v);
  add(ind + 1, cnt + 1, num * v[ind], v);
}
void remove(int ind, int cnt, int num, const vector<int> &v) {
  if (ind == v.size()) return;
  if (cnt % 2 == 0)
    ans -= --freq[num * v[ind]];
  else
    ans += --freq[num * v[ind]];
  remove(ind + 1, cnt, num, v);
  remove(ind + 1, cnt + 1, num * v[ind], v);
}
int main() {
  for (long long i = 2; i < M; i++) {
    if (primes[i].size()) continue;
    primes[i].push_back(i);
    for (long long j = i + i; j < M; j += i) primes[j].push_back(i);
  }
  int q, ind;
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; i++) scanf("%d", arr + i);
  while (q--) {
    scanf("%d", &ind);
    ind--;
    if (on[ind] ^= 1) {
      sz++;
      add(0, 0, 1, primes[arr[ind]]);
    } else {
      sz--;
      remove(0, 0, 1, primes[arr[ind]]);
    }
    printf("%lld\n", sz * (sz - 1) / 2 - ans);
  }
  return 0;
}
