#include <bits/stdc++.h>
using namespace std;
vector<long long> factors[600000];
long long ns[600000];
long long n, q;
void factor(long long j) {
  long long n = ns[j];
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0) {
      factors[j].push_back(i);
      while (n % i == 0) n /= i;
    }
  if (n != 1) factors[j].push_back(n);
}
void init() {
  for (long long i = 0; i < n; i++) factor(i);
}
bool visited[600000];
long long cnt[600000];
int main() {
  cin >> n >> q;
  for (long long i = 0; i < n; i++) cin >> ns[i];
  init();
  long long ans = 0;
  while (q--) {
    long long qt;
    cin >> qt;
    qt--;
    if (!visited[qt]) {
      visited[qt] = true;
      long long len = factors[qt].size();
      for (long long i = 0; i < (1 << len); i++) {
        long long nums = 0;
        long long base = 1;
        for (long long j = 0; j < len; j++)
          if (i & (1 << j)) {
            nums++;
            base *= factors[qt][j];
          }
        if (nums % 2 == 0)
          ans += cnt[base];
        else
          ans -= cnt[base];
        cnt[base]++;
      }
    } else {
      visited[qt] = false;
      long long len = factors[qt].size();
      for (long long i = 0; i < (1 << len); i++) {
        long long nums = 0;
        long long base = 1;
        for (long long j = 0; j < len; j++)
          if (i & (1 << j)) {
            nums++;
            base *= factors[qt][j];
          }
        cnt[base]--;
        if (nums % 2 != 0)
          ans += cnt[base];
        else
          ans -= cnt[base];
      }
    }
    cout << ans << endl;
  }
}
