#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int freq[3 * maxn];
int vol[maxn], n, m, exist[maxn];
long long ans, len;
const int maxprime = 1e6 + 10, up = sqrt(maxprime);
int prime[maxprime];
inline void sieve() {
  for (int i = 0; i < maxprime; i++) prime[i] = i;
  for (int i = 2; i < maxprime; i += 2) prime[i] = 2;
  for (int i = 3; i <= up; i += 2) {
    if (prime[i] != i) continue;
    int lim = i * i;
    int add = 2 * i;
    for (int j = lim; j < maxprime; j += add) {
      if (prime[j] == j) prime[j] = i;
    }
  }
}
long long solve(long long num) {
  long long temp = num, div, val = 0;
  vector<int> seq;
  while (temp > 1) {
    div = prime[temp];
    seq.push_back(div);
    while (temp % div == 0) temp /= div;
  }
  int lim = (1 << seq.size()) - 1;
  for (int i = 1; i <= lim; i++) {
    bitset<8> b(i);
    div = 1;
    for (int j = 0; j < 8; j++) {
      if (b[j] == 1) div *= seq[j];
    }
    if (b.count() % 2 == 0)
      val -= freq[div];
    else
      val += freq[div];
  }
  return val;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  sieve();
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> vol[i];
  while (m--) {
    int first;
    cin >> first;
    if (exist[first] == 0) {
      int temp = solve(vol[first]);
      ans += (len - temp);
      int lim = sqrt(vol[first]);
      for (int i = 1; i <= lim; i++) {
        if (vol[first] % i == 0) {
          freq[i]++;
          int j = vol[first] / i;
          if (j != i) freq[j]++;
        }
      }
      len++;
      exist[first] = 1;
    } else {
      int lim = sqrt(vol[first]);
      for (int i = 1; i <= lim; i++) {
        if (vol[first] % i == 0) {
          freq[i]--;
          int j = vol[first] / i;
          if (j != i) freq[j]--;
        }
      }
      int temp = solve(vol[first]);
      len--;
      ans -= (len - temp);
      exist[first] = 0;
    }
    cout << ans << '\n';
  }
  return 0;
}
