#include <bits/stdc++.h>
using namespace std;
long long int a[500009], came[500009], prime[500009], pairs, multiple[500009],
    tot;
vector<long long int> factor[500009];
void seive() {
  for (long long int i = 2; i <= 500000; i++) {
    if (!prime[i]) {
      for (long long int j = 2 * i; j <= 500000; j += i) {
        prime[j] = 1;
        factor[j].emplace_back(i);
      }
      factor[i].emplace_back(i);
    }
  }
}
void add(long long int no) {
  long long int size = factor[no].size();
  long long int temp = 0;
  for (long long int mask = 1; mask < (1 << size); mask++) {
    long long int prod = 1;
    for (long long int i = 0; i < size; i++) {
      if (mask & (1 << i)) prod *= factor[no][i];
    }
    if ((__builtin_popcount(mask) % 2) == 0)
      temp -= multiple[prod];
    else
      temp += multiple[prod];
  }
  pairs += tot - temp;
  for (long long int mask = 0; mask < (1 << size); mask++) {
    long long int prod = 1;
    for (long long int i = 0; i < size; i++) {
      if (mask & (1 << i)) prod *= factor[no][i];
    }
    multiple[prod]++;
  }
}
void remov(long long int no) {
  long long int size = factor[no].size();
  long long int temp = 0;
  for (long long int mask = 0; mask < (1 << size); mask++) {
    long long int prod = 1;
    for (long long int i = 0; i < size; i++) {
      if (mask & (1 << i)) prod *= factor[no][i];
    }
    multiple[prod]--;
  }
  for (long long int mask = 1; mask < (1 << size); mask++) {
    long long int prod = 1;
    for (long long int i = 0; i < size; i++) {
      if (mask & (1 << i)) prod *= factor[no][i];
    }
    if (__builtin_popcount(mask) % 2 == 0)
      temp -= multiple[prod];
    else
      temp += multiple[prod];
  }
  pairs = pairs - (tot - temp);
}
int main() {
  ios::sync_with_stdio(false);
  ;
  cin.tie(0);
  ;
  long long int i, j, n, q, id;
  seive();
  cin >> n >> q;
  for (i = 0; i < n; i++) cin >> a[i];
  while (q--) {
    cin >> id;
    id--;
    if (came[id]) {
      came[id] = 0;
      tot--;
      remov(a[id]);
      cout << pairs << "\n";
    } else {
      came[id] = 1;
      add(a[id]);
      tot++;
      cout << pairs << "\n";
    }
  }
  return 0;
}
