#include <bits/stdc++.h>
using namespace std;
int a[500005];
int f[500005];
int tak[500005];
int cot[500005];
int d[500005];
int main() {
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    cin >> f[i];
  }
  long long ans = 0;
  long long num = 0;
  long long dec = 0;
  for (int i = 1, x, X; i <= q; ++i) {
    cin >> X;
    x = f[X];
    int cur = num;
    int factor = 1;
    if (!tak[X]) {
      tak[X] = true;
    } else {
      tak[X] = false;
      factor = -1;
    }
    vector<int> v;
    for (int j = 2; j <= x / j; ++j)
      if (x % j == 0) {
        while (x % j == 0) x /= j;
        v.push_back(j);
      }
    if (x != 1) v.push_back(x);
    n = v.size();
    if (factor == 1) {
      for (int m = 1; m < (1 << n); ++m) {
        int mul = 1;
        int cnt = 0;
        for (int j = 0; j < n; ++j) {
          if ((m >> j) & 1) mul *= v[j], cnt++;
        }
        if (cnt & 1) {
          dec += factor * (d[mul]);
          d[mul] += factor;
        } else {
          dec -= factor * (d[mul]);
          d[mul] += factor;
        }
      }
      num += factor;
      cout << ((num * (num - 1)) / 2 - dec) << endl;
    } else {
      for (int m = 1; m < (1 << n); ++m) {
        int mul = 1;
        int cnt = 0;
        for (int j = 0; j < n; ++j) {
          if ((m >> j) & 1) mul *= v[j], cnt++;
        }
        if (cnt & 1) {
          d[mul] += factor;
          dec += factor * (d[mul]);
        } else {
          d[mul] += factor;
          dec -= factor * (d[mul]);
        }
      }
      num += factor;
      cout << ((num * (num - 1)) / 2 - dec) << endl;
    }
  }
}
