#include <bits/stdc++.h>
using namespace std;
const int N = 5 * 100 * 1000;
const int Size = 2 * 100 * 1000;
int n, Q;
int ary[Size];
vector<int> factor[N + 1];
vector<int> asdiv[N + 1];
int number[N + 1];
bool exist[Size];
void preprocess();
void readArray();
void initializeASquares();
void getASquares(int);
void readQueries();
void check(int);
void add(int);
void remove(int);
void update(int, int);
int score(int);
int main() {
  preprocess();
  readArray();
  initializeASquares();
  readQueries();
  return 0;
}
void preprocess() {
  for (int i = 2; i <= N; i++) {
    if (factor[i].size() == 0) {
      int coe = i;
      while (coe <= N) {
        factor[coe].push_back(i);
        coe += i;
      }
    }
  }
}
void readArray() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> Q;
  for (int i = 0; i < n; i++) cin >> ary[i];
}
void initializeASquares() {
  for (int i = 0; i < n; i++) {
    int m = ary[i];
    if (asdiv[m].size() == 0) getASquares(m);
  }
}
void getASquares(int m) {
  int numberOfFactors = factor[m].size();
  int loop = 1 << numberOfFactors;
  for (int i = 1; i < loop; i++) {
    int bitmask = i;
    int aSquare = 1;
    int j = 0;
    while (bitmask > 0) {
      if (bitmask % 2 == 1) aSquare *= factor[m][j];
      bitmask >>= 1;
      j++;
    }
    asdiv[m].push_back(aSquare);
  }
}
void readQueries() {
  long long int ans = 0;
  int size = 0;
  for (int i = 0; i < Q; i++) {
    int ind;
    cin >> ind;
    ind--;
    int s = score(ind);
    if (exist[ind]) {
      ans -= size - s;
      remove(ind);
      size--;
      if (ary[ind] == 1) ans++;
    } else {
      ans += size - s;
      add(ind);
      size++;
    }
    exist[ind] = !exist[ind];
    cout << ans << endl;
  }
}
void check(int ind) {
  cerr << "number " << ary[ind] << " is added." << endl;
  for (int i = 2; i <= N; i++) {
    if (number[i] > 0) {
      cerr << '(';
      for (int j = 0; j < factor[i].size(); j++) {
        if (j > 0) cerr << ',';
        cerr << ' ' << factor[i][j];
      }
      cerr << " ): " << number[i] << endl;
    }
  }
}
void add(int ind) { update(ary[ind], +1); }
void remove(int ind) { update(ary[ind], -1); }
void update(int m, int value) {
  vector<int>::iterator it = asdiv[m].begin();
  while (it != asdiv[m].end()) {
    int aSquare = *it;
    number[aSquare] += value;
    it++;
  }
}
int score(int ind) {
  int m = ary[ind];
  int res = 0;
  vector<int>::iterator it = asdiv[m].begin();
  while (it != asdiv[m].end()) {
    int aSquare = *it;
    if (factor[aSquare].size() % 2 == 0)
      res -= number[aSquare];
    else
      res += number[aSquare];
    it++;
  }
  return res;
}
