#include <bits/stdc++.h>
using namespace std;
int N, Q;
int A[200100], onShelf[200100];
int prime[500100], viz[500100];
int mask[500100];
vector<int> divisors[200100];
vector<int> primes;
void ciur() {
  for (int i = 2; i < 500100; i++) {
    if (!viz[i]) {
      prime[i] = 1;
      for (int j = i; j < 500100; j += i) {
        viz[j] = 1;
      }
    }
  }
}
long long getExclusions(int idx, int toAdd) {
  int sz = divisors[idx].size();
  long long currSol = 0;
  for (int i = 0; i < (1 << sz); i++) {
    int aux = i;
    int currD = 1;
    int nrDiv = 0;
    for (int j = 0; j < sz; j++) {
      if (aux % 2 == 1) {
        currD *= divisors[idx][j];
        nrDiv++;
      }
      aux = aux / 2;
    }
    if (currD > 1) {
      if (nrDiv % 2 == 1) {
        currSol += mask[currD];
      } else {
        currSol -= mask[currD];
      }
      mask[currD] += toAdd;
    }
  }
  return currSol;
}
int main() {
  cin >> N >> Q;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  ciur();
  for (int i = 2; i < 500100; i++) {
    if (prime[i]) primes.push_back(i);
  }
  for (int i = 1; i <= N; i++) {
    int rad = sqrt(A[i]) + 1;
    bool any = false;
    for (int j = 2; j <= rad; j++) {
      if (A[i] % j == 0) {
        if (prime[j]) {
          any = true;
          divisors[i].push_back(j);
        }
        int inverse = A[i] / j;
        if (inverse > rad && prime[inverse]) {
          any = true;
          divisors[i].push_back(inverse);
        }
      }
    }
    if (!any) {
      divisors[i].push_back(A[i]);
    }
  }
  long long sol = 0;
  int number = 0;
  int numberOne = 0;
  while (Q--) {
    int x;
    cin >> x;
    if (onShelf[x]) {
      if (A[x] == 1) {
        sol -= (number - 1);
        numberOne--;
      } else {
        long long inverseSol = getExclusions(x, -1);
        sol -= (number - numberOne) - inverseSol;
        sol -= numberOne;
      }
      onShelf[x] = false;
      number--;
    } else {
      if (A[x] == 1) {
        sol += number;
        numberOne++;
      } else {
        long long inverseSol = getExclusions(x, +1);
        sol += (number - numberOne) - inverseSol;
        sol += numberOne;
      }
      onShelf[x] = true;
      number++;
    }
    cout << sol << '\n';
  }
  return 0;
}
