#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
const long long int mod = 1e9 + 7;
const long long int inf = 1e18;
long long int c[N], a[N];
bool mark[N];
vector<long long int> p[N];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; i++) cin >> a[i];
  int cnt = 0;
  for (int i = 2; i < N; i++) {
    if (!mark[i]) {
      for (int j = i; j < N; j += i) {
        p[j].push_back(i);
        mark[j] = true;
      }
    }
  }
  for (int i = 0; i < N; i++) mark[i] = false;
  long long int ans = 0;
  while (q--) {
    int k;
    cin >> k;
    k--;
    long long int x = a[k];
    long long int d = 0;
    for (int mask = 0; mask < (1 << p[x].size()); mask++) {
      long long int pr = 1;
      for (int j = 0; j < p[x].size(); j++) {
        if ((mask >> j) & 1) pr *= p[x][j];
      }
      if (mark[k]) c[pr]--;
      if (__builtin_popcount(mask) % 2 == 0)
        d += c[pr];
      else
        d -= c[pr];
      if (!mark[k]) c[pr]++;
    }
    if (mark[k]) {
      mark[k] = false;
      ans -= d;
    } else {
      mark[k] = true;
      ans += d;
    }
    cout << ans << endl;
  }
  return 0;
}
