#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, A = 5e5 + 10;
int a[N], cnt[A], dp[A];
vector<int> p[A];
bool is[A];
long long add(int first, int val) {
  long long ret = 0;
  for (int mask = 0; mask < (1 << ((int)(p[first]).size())); mask++) {
    if (!mask)
      dp[0] = 1;
    else
      dp[mask] = dp[mask & (mask - 1)] * p[first][__builtin_ctz(mask)];
    int d = dp[mask];
    int mobius = (__builtin_popcount(mask) & 1) ? -1 : 1;
    ret -= mobius * cnt[d] * 1LL * (cnt[d] - 1) / 2;
    cnt[d] += val;
    ret += mobius * cnt[d] * 1LL * (cnt[d] - 1) / 2;
  }
  return ret;
}
int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 2; i < A; i++)
    if (p[i].empty()) {
      for (int j = i; j < A; j += i) {
        p[j].push_back(i);
      }
    }
  long long ans = 0;
  while (q--) {
    int first;
    scanf("%d", &first);
    ans += add(a[first], is[first] ? -1 : 1);
    is[first] ^= 1;
    printf("%lld\n", ans);
  }
  return 0;
}
