#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9 + 7;
const int maxn = 5e5 + 7;
long long m, n, pop[500], in[maxn], x, p[maxn], t[10], d[maxn], a[maxn];
long long ans;
inline void read(long long &x) {
  register int c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
inline void writeln(long long x) {
  char buffor[21];
  register int i = 0;
  int neg = 0;
  if (x < 0) {
    neg = 1;
    x = -x;
  }
  do {
    buffor[i++] = (x % 10) + '0';
    x /= 10;
  } while (x);
  i--;
  if (neg) putchar('-');
  while (i >= 0) putchar(buffor[i--]);
  putchar('\n');
}
void nhap() {
  read(n);
  read(m);
  for (int i = (1), _b = (n); i <= _b; ++i) read(a[i]);
}
inline void sieve() {
  for (int i = (1), _b = (maxn - 1); i <= _b; ++i) p[i] = i;
  for (int i = (2), _b = (trunc(sqrt(maxn))); i <= _b; ++i)
    if (p[i] == i)
      for (int j = (i), _b = (maxn / i); j <= _b; ++j) p[i * j] = i;
}
inline int checkbit(int pos, int x) { return (x >> pos) & 1; }
inline void Update(int id, int x) {
  int g = 0, savex = x;
  while (savex > 1) {
    t[++g] = p[savex];
    while (savex % t[g] == 0) savex /= t[g];
  }
  for (int i = (0), _b = ((1 << g) - 1); i <= _b; ++i) {
    int tmp = 1;
    for (int j = (1), _b = (g); j <= _b; ++j)
      if (checkbit(j - 1, i)) tmp *= t[j];
    int Sign = (pop[i] & 1) ? -1 : 1;
    if (in[id] == 1) {
      d[tmp] += in[id] * -1;
      ans += -1 * Sign * d[tmp];
    } else {
      ans += Sign * d[tmp];
      d[tmp] += in[id] * -1;
    }
  }
  in[id] *= -1;
}
void solve() {
  sieve();
  for (int i = (0), _b = (499); i <= _b; ++i) {
    pop[i] = __builtin_popcount(i);
  }
  memset(in, -1, sizeof(in));
  for (int i = (1), _b = (m); i <= _b; ++i) {
    read(x);
    Update(x, a[x]);
    writeln(ans);
  }
}
void print() {}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  nhap();
  solve();
  print();
}
