#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 200000;
const int MAX_P = 6;
const int MAX_E = 500000;
struct GCDSolver {
  int v[1 + MAX_N];
  bool exista[1 + MAX_N];
  vector<int> primes[1 + MAX_E];
  int popcnt[1 << MAX_P], lsb[1 << MAX_P], prod[1 << MAX_P], fr[MAX_E];
  int size;
  long long goodpairs;
  void init() {
    for (int d = 2; d <= MAX_E; ++d)
      if (primes[d].empty())
        for (int i = d; i <= MAX_E; i += d) primes[i].push_back(d);
    for (int i = 1; i < (1 << MAX_P); ++i) {
      popcnt[i] = popcnt[i & (i - 1)] + 1;
      if (i % 2 == 1)
        lsb[i] = 0;
      else
        lsb[i] = lsb[i / 2] + 1;
    }
  }
  bool existaNr(int i) { return exista[i]; }
  void insert(int i) {
    int val = v[i], allmsk = (1 << (int)primes[val].size()) - 1;
    prod[0] = 1;
    for (int msk = 1; msk < (1 << (int)primes[val].size()); ++msk) {
      prod[msk] = prod[msk ^ (1 << lsb[msk])] * primes[val][lsb[msk]];
      if (popcnt[msk] % 2 == 1)
        goodpairs += fr[prod[msk]];
      else
        goodpairs -= fr[prod[msk]];
      fr[prod[msk]]++;
    }
    exista[i] = true;
    size++;
  }
  void erase(int i) {
    int val = v[i], allmsk = (1 << (int)primes[val].size()) - 1;
    prod[0] = 1;
    for (int msk = 1; msk < (1 << (int)primes[val].size()); ++msk) {
      prod[msk] = prod[msk ^ (1 << lsb[msk])] * primes[val][lsb[msk]];
      fr[prod[msk]]--;
      if (popcnt[msk] % 2 == 1)
        goodpairs -= fr[prod[msk]];
      else
        goodpairs += fr[prod[msk]];
    }
    exista[i] = false;
    size--;
  }
  long long queryPairs() {
    return (long long)size * (size - 1) / 2 - goodpairs;
  }
} solver;
int main() {
  int n, m, x;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &solver.v[i]);
  solver.init();
  for (int i = 0; i < m; ++i) {
    scanf("%d", &x);
    if (solver.existaNr(x))
      solver.erase(x);
    else
      solver.insert(x);
    printf("%lld\n", solver.queryPairs());
  }
  return 0;
}
