#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  long long r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int n, q;
int a[200001];
bool s[200001];
int cnt[500001];
vector<int> d[500001];
void solve() {
  memset(s, 0, sizeof(s));
  memset(cnt, 0, sizeof(cnt));
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    int temp = a[i];
    for (int j = 2; j * j <= temp; j++) {
      if (temp % j == 0) {
        while (temp % j == 0) temp /= j;
        d[i].push_back(j);
      }
    }
    if (temp > 1) d[i].push_back(temp);
  }
  long long ans = 0;
  while (q--) {
    int x;
    cin >> x;
    x--;
    for (int i = 0; i < 1 << d[x].size(); i++) {
      int y = 1, num = 0;
      for (int j = 0; j < d[x].size(); j++)
        if (i & (1 << j)) {
          y *= d[x][j];
          num++;
        }
      if (s[x])
        ans -= (num % 2 == 0 ? 1 : -1) * (--cnt[y]);
      else
        ans += (num % 2 == 0 ? 1 : -1) * (cnt[y]++);
    }
    s[x] = !s[x];
    cout << ans << "\n";
  }
}
int main() {
  solve();
  return 0;
}
