#include <bits/stdc++.h>
using namespace std;
const int INF = std::numeric_limits<int>::max() / 3;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
vector<vector<long long> > PF;
bitset<500500> isprime;
vector<long long> primes, A, Cnt;
void sieve() {
  isprime.set();
  isprime[0] = isprime[1] = false;
  for (int i = 2; i * i < 500500; ++i)
    if (isprime[i])
      for (int j = i * i; j < 500500; j += i) isprime[j] = false;
  PF.assign(500500, vector<long long>());
  for (int i = 2; i < 500500; ++i)
    if (isprime[i])
      for (int j = i; j < 500500; j += i) {
        PF[j].push_back(i);
      }
}
void update(int N, int sign) {
  int pf = PF[N].size();
  for (int i = 0; i < (1 << pf); ++i) {
    long long p = 1;
    for (int j = 0; j < pf; ++j)
      if (i & (1 << j)) p *= PF[N][j];
    Cnt[p] += sign;
  }
}
long long pairs(int N) {
  int pf = PF[N].size();
  long long ans = 0;
  for (int i = 0; i < (1 << pf); ++i) {
    long long p = 1;
    for (int j = 0; j < pf; ++j) {
      if (i & (1 << j)) {
        p *= PF[N][j];
      }
    }
    if (PF[p].size() % 2 == 1)
      ans -= Cnt[p];
    else
      ans += Cnt[p];
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  sieve();
  int n, q;
  vector<long long> inShelf;
  cin >> n >> q;
  inShelf.assign(n, 1);
  for (int i = 0, t; i < n; ++i) {
    cin >> t;
    A.push_back(t);
  }
  long long total = 0;
  Cnt.assign(500500 + 100000, 0);
  for (int i = 0; i < q; ++i) {
    int j;
    cin >> j;
    j--;
    if (inShelf[j] > 0) {
      total += pairs(A[j]);
      update(A[j], inShelf[j]);
    } else {
      update(A[j], inShelf[j]);
      total -= pairs(A[j]);
    }
    inShelf[j] *= -1;
    cout << total << endl;
  }
  return 0;
}
