#include <bits/stdc++.h>
using namespace std;
const int N = 500000;
int lp[N + 1];
vector<int> pr, primes[500001];
int multiplesOf[500001], beers[500001];
long long int allpairs = 0;
bool inShelf[500001];
void sieve() {
  for (int i = 2; i < 500001; i++)
    if (primes[i].size() == 0)
      for (int j = i; j < 500001; j = j + i) primes[j].push_back(i);
}
int kitnoSeGCD(int num) {
  if (num == 1) return -multiplesOf[1];
  int count = 0;
  vector<int>& mis = primes[num];
  int limit = (1 << mis.size());
  for (int i = 0; i < limit; i++) {
    int my = 1;
    for (int j = 0; j < mis.size(); j++)
      if (i & (1 << j)) my = my * mis[j];
    if ((__builtin_popcount(i) % 2) == 0)
      count = count - multiplesOf[my];
    else
      count = count + multiplesOf[my];
  }
  return count;
}
void add(int num, int remove = 0) {
  if (remove == 0) allpairs = allpairs - kitnoSeGCD(num);
  vector<int>& mis = primes[num];
  int limit = (1 << mis.size());
  for (int i = 0; i < limit; i++) {
    int my = 1;
    for (int j = 0; j < mis.size(); j++) {
      if (i & (1 << j)) my = my * mis[j];
    }
    if (remove)
      multiplesOf[my]--;
    else
      multiplesOf[my]++;
  }
  if (remove) allpairs = allpairs + kitnoSeGCD(num);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  ;
  sieve();
  int n, q, sc;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    cin >> beers[i];
  }
  for (int i = 0; i < q; i++) {
    cin >> sc;
    add(beers[sc - 1], inShelf[sc - 1]);
    inShelf[sc - 1] = 1 - inShelf[sc - 1];
    cout << allpairs << endl;
  }
  return 0;
}
