#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
using namespace std;
const long long N = 5e5 + 1;
const long long mod = 998244353;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
long long test = 1, n, q, a[N], vis[N], inc[N], spf[N], ct[N];
vector<long long> fact[N];
long long no_of_coprimes(int x) {
  long long res = 0;
  for (auto it : fact[x]) res += ct[it] * inc[it];
  return res;
}
void solve() {
  for (int i = 1; i < N; i++) {
    for (int j = i; j < N; j += i) fact[j].push_back(i);
    spf[i] = fact[i][1];
    if (i == 1)
      inc[i] = 1;
    else if ((i / spf[i]) % spf[i] == 0)
      inc[i] = 0;
    else
      inc[i] = -inc[i / spf[i]];
  }
  long long ans = 0;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) cin >> a[i];
  while (q--) {
    int x;
    cin >> x;
    if (vis[x] == 0) {
      vis[x] = 1;
      ans += no_of_coprimes(a[x]);
      for (auto it : fact[a[x]]) ct[it]++;
    } else {
      vis[x] = 0;
      for (auto it : fact[a[x]]) ct[it]--;
      ans -= no_of_coprimes(a[x]);
    }
    cout << ans << "\n";
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed;
  cout << setprecision(15);
  ;
  for (int i = 1; i <= test; i++) {
    solve();
  }
}
