#include <bits/stdc++.h>
using namespace std;
bool p[200005];
long long int ans = 0;
long long int a[200005];
vector<long long int> divi[500005];
long long int sp[500005];
bool v[500005];
void Sieve() {
  for (long long int i = 2; i <= 500000; i++) {
    if (sp[i]) {
      continue;
    }
    sp[i] = i;
    for (long long int j = i * i; j <= 500000; j += i) {
      if (sp[j] == 0) {
        sp[j] = i;
      }
    }
  }
}
long long int co[500005];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  Sieve();
  for (long long int i = 1; i <= 500000; i++) {
    for (long long int j = i; j <= 500000; j += i) {
      divi[j].push_back(i);
    }
  }
  long long int n, q;
  cin >> n >> q;
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  long long int curr = 0;
  while (q--) {
    long long int x;
    cin >> x;
    if (p[x]) {
      long long int c = 0;
      vector<long long int> pr;
      long long int w = a[x];
      while (w > 1) {
        long long int y = sp[w];
        pr.push_back(y);
        while (w % y == 0) {
          w /= y;
        }
      }
      for (long long int i = 1; i < (1 << (pr.size())); i++) {
        long long int zz = 1;
        long long int cou = 0;
        for (long long int j = 0; j < pr.size(); j++) {
          if (i & (1 << j)) {
            zz *= pr[j];
            cou++;
          }
        }
        if (cou % 2 == 1) {
          c += co[zz];
        } else {
          c -= co[zz];
        }
      }
      ans -= curr - c;
      if (a[x] == 1) {
        ans++;
      }
      for (long long int xy : divi[a[x]]) {
        co[xy]--;
      }
      p[x] = 0;
      curr--;
    } else {
      long long int c = 0;
      vector<long long int> pr;
      long long int w = a[x];
      while (w > 1) {
        long long int y = sp[w];
        pr.push_back(y);
        while (w % y == 0) {
          w /= y;
        }
      }
      for (long long int i = 1; i < (1 << (pr.size())); i++) {
        long long int zz = 1;
        long long int cou = 0;
        for (long long int j = 0; j < pr.size(); j++) {
          if (i & (1 << j)) {
            zz *= pr[j];
            cou++;
          }
        }
        if (cou % 2 == 1) {
          c += co[zz];
        } else {
          c -= co[zz];
        }
      }
      ans += curr - c;
      for (long long int xy : divi[a[x]]) {
        co[xy]++;
      }
      p[x] = 1;
      curr++;
    }
    cout << ans << "\n";
  }
}
