#include <bits/stdc++.h>
using namespace std;
struct vec {
  long double x, y;
  bool operator==(const vec &a) const { return x == a.x && y == a.y; }
  bool operator<(const vec &a) const {
    if (a.x != x) return x < a.x;
    return y < a.y;
  }
  vec operator+(const vec &a) const { return {x + a.x, y + a.y}; }
  vec operator*(const long double &a) const { return {x * a, y * a}; }
  vec operator-(const vec &a) const { return {x - a.x, y - a.y}; }
  vec operator/(const long double &a) const { return {x / a, y / a}; }
  long double len() const { return sqrt(x * x + y * y); }
  long double dot(const vec &a) const { return x * a.x + y * a.y; }
  long double crs(const vec &a) const { return x * a.y - y * a.x; }
  vec proj(const vec &a) const {
    return (a / a.len()) * (*this).dot(a) / a.len();
  }
};
struct P {
  int x, y;
  bool operator<(const P &a) const {
    if (x != a.x) return x > a.x;
    return y < a.y;
  }
};
bool as(P a, P b) { return a.x < b.x; }
long long x, y, z, mod = 1000000007;
vector<int> v1, v, v2;
int i, n, m, k, a, d, b, c, dx[10] = {1, 0, -1, 0}, dy[10] = {0, 1, 0, -1};
int e[511112];
int l[511155];
int o[511110];
int j[511112];
stack<int> s;
queue<int> q, q1;
P u[533111];
string r, r1;
map<int, int> p, p1;
int main() {
  scanf("%d %d", &a, &b);
  for (int t = 1; t <= a; t++) scanf("%d", &j[t]);
  for (int t = 1; t <= b; t++) {
    v.clear();
    scanf("%d", &n);
    d = n;
    e[d] = 1 - e[d];
    n = j[n];
    if (n == 1) {
      c -= o[n];
      if (e[d])
        o[n]++;
      else
        o[n]--;
      c += o[n];
      goto qwe;
    }
    m = n;
    for (int i = 2; i * i <= n; i++) {
      if (n % i == 0) {
        v.push_back(i);
        for (; n % i == 0; n /= i)
          ;
      }
    }
    if (n > 1) v.push_back(n);
    n = m;
    c -= o[n];
    if (e[d])
      o[n]++;
    else
      o[n]--;
    c += o[n];
    for (int i = 1; i < (1 << v.size()); i++) {
      int k = 0, p = 1;
      for (int t = i, j = 0; t; j++, k += t % 2, k %= 2, t /= 2)
        if (t % 2) p *= v[j];
      if (e[d]) {
        if (k)
          x += l[p];
        else
          x -= l[p];
        l[p]++;
      } else {
        l[p]--;
        if (k)
          x -= l[p];
        else
          x += l[p];
      }
    }
  qwe:;
    printf("%lld\n", (long long)c * (c - 1) / 2 - x);
  }
}
