#include <bits/stdc++.h>
using namespace std;
const int MAXA = 500005, MAXN = 200005;
vector<int> v[MAXN];
int cnt[MAXA], n, q, a[MAXN], shelf[MAXN], t, size;
long long ans = 0;
void upd(int x) {
  int mul = 1, count, val, gcd1 = size;
  if (shelf[x] == 1) mul = -1;
  shelf[x] ^= 1;
  for (int i = 1; i < (1 << (int)v[x].size()); ++i) {
    count = 0, val = 1;
    for (int j = 0; j < v[x].size(); ++j)
      if (i & (1 << j)) {
        ++count;
        val *= v[x][j];
      }
    if (count & 1)
      gcd1 -= cnt[val];
    else
      gcd1 += cnt[val];
    cnt[val] += mul;
  }
  if (a[x] == 1 && shelf[x] == 0) --gcd1;
  ans += mul * gcd1;
  if (shelf[x] == 0)
    --size;
  else
    ++size;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    t = a[i];
    for (int j = 2; j * j <= t; ++j) {
      if (t % j == 0) {
        v[i].push_back(j);
        while (t % j == 0) t /= j;
      }
    }
    if (t != 1) v[i].push_back(t);
  }
  for (int i = 0; i < q; ++i) {
    cin >> t;
    upd(t);
    cout << ans << '\n';
  }
}
