#include <bits/stdc++.h>
using namespace std;
int mobius[500005], prime_cnt[500005], prime[500005], present[500005],
    nums[500005], cnt[500005];
vector<int> divisors[500005];
void calc_divisors(int val) {
  int i;
  if (divisors[val].size() > 0) return;
  int foo = sqrt(val);
  for (i = 1; i <= foo; i++) {
    if ((val % i) == 0) {
      divisors[val].push_back(i);
      divisors[val].push_back(val / i);
    }
  }
  if ((foo * foo) == val) {
    int temp = divisors[val].size();
    divisors[val][temp - 1] = 0;
  }
  return;
}
void calc_mobius() {
  mobius[0] = 0;
  long long int i, j, temp;
  prime[1] = 1;
  mobius[1] = 1;
  for (i = 2; i < 500005; i++) {
    if (prime[i] == 0) {
      for (j = 2 * i; j < 500005; j += i) {
        prime[j] = 1;
        prime_cnt[j]++;
      }
      temp = i * i;
      j = 1;
      while (temp < 500005) {
        mobius[temp] = 0;
        j++;
        temp = j * i * i;
      }
      mobius[i] = -1;
    } else {
      if (mobius[i] == 500005) {
        if ((prime_cnt[i] % 2) == 0)
          mobius[i] = 1;
        else
          mobius[i] = -1;
      }
    }
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  ;
  int i, j, t, n, m, k, l, r, temp, mini, maxi, flag;
  long long int result = 0LL;
  for (i = 0; i < 500005; i++) {
    mobius[i] = 500005;
    prime[i] = 0;
    prime_cnt[i] = 0;
    cnt[i] = 0;
    present[i] = 0;
  }
  calc_mobius();
  divisors[1].push_back(1);
  divisors[2].push_back(1);
  divisors[2].push_back(2);
  divisors[3].push_back(1);
  divisors[3].push_back(3);
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> nums[i];
    calc_divisors(nums[i]);
  }
  for (i = 0; i < m; i++) {
    cin >> k;
    temp = nums[k];
    if (present[k] == 0) {
      present[k] = 1;
      for (j = 0; j < divisors[temp].size(); j++) {
        result = result + (long long int)mobius[divisors[temp][j]] *
                              cnt[divisors[temp][j]];
        cnt[divisors[temp][j]]++;
      }
    } else {
      present[k] = 0;
      for (j = 0; j < divisors[temp].size(); j++) {
        result = result - (long long int)mobius[divisors[temp][j]] *
                              (cnt[divisors[temp][j]] - 1LL);
        cnt[divisors[temp][j]]--;
      }
    }
    cout << result << endl;
  }
  return 0;
}
