#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Foreach(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define rof(i,a,b) for(int (i)=(a);(i) > (b); --(i))
#define rep(i, c) for(auto &(i) : (c))
#define x first
#define y second
#define pb push_back
#define PB pop_back()
#define iOS ios_base::sync_with_stdio(false)
#define sqr(a) (((a) * (a)))
#define all(a) a.begin() , a.end()
#define error(x) cerr << #x << " = " << (x) <<endl
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define errop(a) cerr<<#a<<" = ( "<<((a).x)<<" , "<<((a).y)<<" )\n";
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define L(x) ((x)<<1)
#define R(x) (((x)<<1)+1)
#define umap unordered_map
#define double long double
typedef long long ll;
typedef pair<int,int>pii;
typedef vector<int> vi;
typedef complex<double> point;
template <typename T> using os = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline void smax(T &x,T y){ x = max((x), (y));}
template <class T> inline void smin(T &x,T y){ x = min((x), (y));}
const int maxn = 1e6 + 10;
int lsp[maxn], cnt[maxn];
ll ans = 0LL;
int a[maxn], p[10], nx, bp[256], dp[256], lb[256], tp[256];
inline void upd(int x, int sgn){
nx = 0;
int a;
while(x > 1){
a = lsp[x];
p[nx ++] = a;
while(x % a == 0)
x /= a;
}
For(mask,0,tp[nx]){
if(mask)
dp[mask] = p[lb[mask]] * dp[mask ^ tp[lb[mask]]];
else
dp[mask] = 1;
if(sgn < 0)
cnt[dp[mask]] += sgn;
if(bp[mask] % 2)
ans += -1LL * sgn * cnt[dp[mask]];
else
ans += +1LL * sgn * cnt[dp[mask]];
if(sgn > 0)
cnt[dp[mask]] += sgn;
}
}
bool in[maxn];
int n, q;
int main(){
memset(lsp, -1, sizeof lsp);
For(i,0,256){
tp[i] = (1 << i);
bp[i] = __builtin_popcount(i);
lb[i] = __builtin_ctz(i);
}
For(i,2,maxn)
if(lsp[i] == -1)
for(int j = i;j < maxn;j += i)
lsp[j] = i;
scanf("%d %d", &n, &q);
For(i,0,n)
scanf("%d", a + i);
while(q--){
int i;
scanf("%d", &i);
-- i;
if(!in[i])
upd(a[i], +1);
else
upd(a[i], -1);
in[i] = !in[i];
printf("%lld\n", ans);
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlIDxleHQvcGJfZHMvYXNzb2NfY29udGFpbmVyLmhwcD4KI2luY2x1ZGUgPGV4dC9wYl9kcy90cmVlX3BvbGljeS5ocHA+CnVzaW5nIG5hbWVzcGFjZSBfX2dudV9wYmRzOwp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIEZvcmVhY2goaSwgYykgZm9yKF9fdHlwZW9mKChjKS5iZWdpbigpKSBpID0gKGMpLmJlZ2luKCk7IGkgIT0gKGMpLmVuZCgpOyArK2kpCiNkZWZpbmUgRm9yKGksYSxiKSBmb3IoaW50IChpKT0oYSk7KGkpIDwgKGIpOyArKyhpKSkKI2RlZmluZSByb2YoaSxhLGIpIGZvcihpbnQgKGkpPShhKTsoaSkgPiAoYik7IC0tKGkpKQojZGVmaW5lIHJlcChpLCBjKSBmb3IoYXV0byAmKGkpIDogKGMpKQojZGVmaW5lIHggZmlyc3QKI2RlZmluZSB5IHNlY29uZAojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIFBCIHBvcF9iYWNrKCkKI2RlZmluZSBpT1MgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSkKI2RlZmluZSBzcXIoYSkgKCgoYSkgKiAoYSkpKQojZGVmaW5lIGFsbChhKSBhLmJlZ2luKCkgLCBhLmVuZCgpCiNkZWZpbmUgZXJyb3IoeCkgY2VyciA8PCAjeCA8PCAiID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