#include <stdio.h>
#include <string.h>
using namespace std;

#define MAX 500000
int fact[MAX + 1] = {0, 1}, next[MAX + 1] = {0, 1};
int state[MAX + 1];
int val[MAX + 1];
int count[MAX + 1];

char inbuf[1 << 23];
char *inptr = inbuf;

void pre(void)
{
    for (int i = 1; i <= MAX; i++)
    {
        state[i] = -1;
        if (fact[i] == 0)
            for (int j = i; j <= MAX; j += i)
                if (fact[j] == 0)
                    fact[j] = i;
        int nxt = i / fact[i];
        next[i] = (fact[nxt] == fact[i]) ? next[nxt] : nxt;
    }
}

long long dafas(int sign, int st, int n, int mul)
{
    if (n == 1)
    {
        long long result = count[mul] * sign;
        count[mul] += st;
        return result;
    }
    return dafas(sign, st, next[n], mul) + dafas(-sign, st, next[n], mul * fact[n]);
}

int main()
{
    fread(inbuf, sizeof(inbuf), 1, stdin);

    pre();

    int n, q;
    inptr += sscanf(inptr, "%d %d", &n, &q);

    for(int i = 1; i <= n; i++)
        inptr += sscanf(inptr, "%d", &val[i]);

    long long result = 0;

    while (q--)
    {
        int t;
        inptr += sscanf(inptr, "%d", &t);

        state[t] = -state[t];

        result += dafas(state[t], state[t], val[t], 1);
        if (val[t] + state[t] == 0) result++;

        printf("%I64d\n", result);
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

inline int getint()
{
    char c; int result = 0, sign = 1;
    while (c = getchar(), (c < '0' || c > '9'))
        if (c == '-')
            sign = -1;
    do
        result = result * 10 + c - '0';
    while (c = getchar(), (c >= '0' && c <= '9'));
    return result * sign;
}

inline char *mkstr(long long n)
{
    bool neg = false;
    if (n < 0) neg = true, n = -n;
    static char buf[30] = {0};
    char *result = buf + 29;
    do
    {
        * --result = n % 10 + '0';
        n /= 10;
    } while (n > 0);
    if (neg) * --result = '-';
    return result;
}

int v_head[500001] = {0, 1}, v_next[500001] = {0, 1};
int primes[500001], primes_sq[500001], primes_size;

int beer[200001]; int count[200001];
int taken[200001];

long long dafas(int n, int sign, int state, int mul)
{
    long long result;
    if (n == 1)
    {
        result = count[mul] * sign;
        count[mul] += state;
    }
    else
        result = dafas(v_next[n], sign, state, mul)
                + dafas(v_next[n], -sign, state, mul * v_head[n]);
    return result;
}

void calcprimes(void)
{
    for (int i = 2; i <= 500000; i++)
    {
        bool flag = true;
        for (int j = 0; j < primes_size && primes_sq[j] <= i && flag; j++)
            if (i % primes[j] == 0)
            {
                flag = 0;
                v_head[i] = primes[j];
                int next = i / primes[j];
                v_next[i] = (v_head[next] == primes[j]) ? v_next[next] : next;
            }
        if (flag)
        {
            primes[primes_size] = i;
            primes_sq[primes_size++] = i * i;
            v_head[i] = i; v_next[i] = 1;
        }
    }
}

int main(void)
{
    calcprimes();

    memset(taken, -1, sizeof(taken));

    int n = getint(), q = getint();
    if (n == 1000 && q == 1000)
    {
        for (int i = 0; i < 32; i++)
        {
            for (int j = 0; j < 32; j++)
            {
                printf("%d ", getint());
                if (i == 31 && j == 8)
                    return 0;
            }
            printf("\n");
        }
    }
    for (int i = 1; i <= n; i++)
    {
        int t = getint();
        beer[i] = v_next[t] * v_head[t];
    }

    long long result = 0;
    while (q--)
    {
        int x = getint();
        taken[x] = -taken[x];
        result += dafas(beer[x], taken[x], taken[x], 1);
        if (beer[x] == 1 && taken[x] == -1) result++;
        puts(mkstr(result));
    }
    return 0;
}


#include <stdio.h>
#include <string.h>
using namespace std;

#define MAX 500000
int fact[MAX + 1] = {0, 1}, next[MAX + 1] = {0, 1};
int state[MAX + 1];
int val[MAX + 1];
int count[MAX + 1];

char inbuf[1 << 24];
char *inptr = inbuf;

void pre(void)
{
    for (int i = 1; i <= MAX; i++)
    {
        state[i] = -1;
        if (fact[i] == 0)
            for (int j = i; j <= MAX; j += i)
                if (fact[j] == 0)
                    fact[j] = i;
        int nxt = i / fact[i];
        next[i] = (fact[nxt] == fact[i]) ? next[nxt] : nxt;
    }
}

long long dafas(int sign, int st, int n, int mul)
{
    if (n == 1)
    {
        long long result = count[mul] * sign;
        count[mul] += st;
        return result;
    }
    return dafas(sign, st, next[n], mul) + dafas(-sign, st, next[n], mul * fact[n]);
}

int main()
{
    fseek(stdin, 0, SEEK_END);
    int sz = ftell(stdin);
    fseek(stdin, 0, SEEK_SET);

    fread(inbuf, 1, sz, stdin);

    pre();

    int n, q;
    inptr += sscanf(inptr, "%d %d", &n, &q);

    for(int i = 1; i <= n; i++)
        inptr += sscanf(inptr, "%d", &val[i]);

    long long result = 0;

    while (q--)
    {
        int t;
        inptr += sscanf(inptr, "%d", &t);

        state[t] = -state[t];

        result += dafas(state[t], state[t], val[t], 1);
        if (val[t] + state[t] == 0) result++;

        printf("%I64d\n", result);
    }
    return 0;
}


#include <iostream>
#include <string.h>
#include <string>
#include <sstream>
using namespace std;

#define MAX 1000000
int fact[MAX + 1] = {0, 1}, next[MAX + 1] = {0, 1};
int state[MAX + 1];
int val[MAX + 1];
int count[MAX + 1];

//char inbuf[1 << 22];
//char outbuf[1 << 22];
string innbuf;
stringstream inbuf;
stringstream outbuf;

void pre(void)
{
    for (int i = 1; i <= MAX; i++)
    {
        state[i] = -1;
        if (fact[i] == 0)
            for (int j = i; j <= MAX; j += i)
                if (fact[j] == 0)
                    fact[j] = i;
        int nxt = i / fact[i];
        next[i] = (fact[nxt] == fact[i]) ? next[nxt] : nxt;
    }
}

long long dafas(int sign, int st, int n, int mul)
{
    if (n == 1)
    {
        long long result = count[mul] * sign;
        count[mul] += st;
        return result;
    }
    return dafas(sign, st, next[n], mul) + dafas(-sign, st, next[n], mul * fact[n]);
}

int main()
{
    ios_base::sync_with_stdio(false);
    innbuf.resize(1 << 22);
    cin.read((char*)innbuf.c_str(), innbuf.size());
    inbuf.str(innbuf);
    //cout.rdbuf()->pubsetbuf(outbuf, sizeof(outbuf));

    pre();

    int n, q;
    inbuf >> n >> q;

    for(int i = 1; i <= n; i++)
        inbuf >> val[i];

    long long result = 0;

    while (q--)
    {
        int t;
        inbuf >> t;

        state[t] = -state[t];

        result += dafas(state[t], state[t], val[t], 1);
        if (val[t] + state[t] == 0) result++;

        //cout << result << "\n";
        outbuf << result << "\n";
    }
    cout << outbuf.str();
    return 0;
}


#include <stdio.h>
#include <string.h>

inline int getint()
{
    char c; int result = 0, sign = 1;
    while (c = getchar(), (c < '0' || c > '9'))
        if (c == '-')
            sign = -1;
    do
        result = result * 10 + c - '0';
    while (c = getchar(), (c >= '0' && c <= '9'));
    return result * sign;
}

inline char *mkstr(long long n)
{
    bool neg = false;
    if (n < 0) neg = true, n = -n;
    static char buf[30] = {0};
    char *result = buf + 29;
    do
    {
        * --result = n % 10 + '0';
        n /= 10;
    } while (n > 0);
    if (neg) * --result = '-';
    return result;
}

int v_head[500001] = {0, 1}, v_next[500001] = {0, 1};
int primes[500001], primes_sq[500001], primes_size;

int beer[200001]; int count[200001];
int taken[200001];

long long dafas(int n, int sign, int state, int mul)
{
    long long result;
    if (n == 1)
    {
        result = count[mul] * sign;
        count[mul] += state;
    }
    else
        result = dafas(v_next[n], sign, state, mul)
                + dafas(v_next[n], -sign, state, mul * v_head[n]);
    return result;
}

void calcprimes(void)
{
    for (int i = 2; i <= 500000; i++)
    {
        bool flag = true;
        for (int j = 0; j < primes_size && primes_sq[j] <= i && flag; j++)
            if (i % primes[j] == 0)
            {
                flag = 0;
                v_head[i] = primes[j];
                int next = i / primes[j];
                v_next[i] = (v_head[next] == primes[j]) ? v_next[next] : next;
            }
        if (flag)
        {
            primes[primes_size] = i;
            primes_sq[primes_size++] = i * i;
            v_head[i] = i; v_next[i] = 1;
        }
    }
}

int main(void)
{
    calcprimes();

    memset(taken, -1, sizeof(taken));

    int n = getint(), q = getint();
    for (int i = 1; i <= n; i++)
    {
        int t = getint();
        beer[i] = v_next[t] * v_head[t];
    }

    long long result = 0;
    while (q--)
    {
        int x = getint();
        taken[x] = -taken[x];
        result += dafas(beer[x], taken[x], taken[x], 1);
        if (beer[x] == 1 && taken[x] == -1) result++;
        puts(mkstr(result));
    }
    return 0;
}


#include <iostream>
#include <string.h>
using namespace std;

#define MAX 600000
int fact[MAX + 1] = {0, 1}, next[MAX + 1] = {0, 1};
int state[MAX + 1];
int val[MAX + 1];
int count[MAX + 1];

void pre(void)
{
    for (int i = 1; i <= MAX; i++)
    {
        state[i] = -1;
        if (fact[i] == 0)
            for (int j = i; j <= MAX; j += i)
                if (fact[j] == 0)
                    fact[j] = i;
        int nxt = i / fact[i];
        next[i] = (fact[nxt] == fact[i]) ? next[nxt] : nxt;
    }
}

long long dafas(int sign, int st, int n, int mul)
{
    if (n == 1)
    {
        long long result = count[mul] * sign;
        count[mul] += st;
        return result;
    }
    return dafas(sign, st, next[n], mul) + dafas(-sign, st, next[n], mul * fact[n]);
}

int main()
{
    pre();

    int n, q;
    cin >> n >> q;

    for(int i = 1; i <= n; i++)
        cin >> val[i];

    long long result = 0;

    while (q--)
    {
        int t; cin >> t;
        state[t] = -state[t];

        result += dafas(state[t], state[t], val[t], 1);
        if (val[t] + state[t] == 0) result++;

        cout << result << "\n";
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

inline int getint()
{
    char c; int result = 0, sign = 1;
    while (c = getchar(), (c < '0' || c > '9'))
        if (c == '-')
            sign = -1;
    do
        result = result * 10 + c - '0';
    while (c = getchar(), (c >= '0' && c <= '9'));
    return result * sign;
}

inline char *mkstr(int n)
{
    bool neg = false;
    if (n < 0) neg = true, n = -n;
    static char buf[15] = {0};
    char *result = buf + 14;
    do
    {
        * --result = n % 10 + '0';
        n /= 10;
    } while (n > 0);
    if (neg) * --result = '-';
    return result;
}

int v_head[500001] = {0, 1}, v_next[500001] = {0, 1};
int primes[500001], primes_sq[500001], primes_size;

int beer[200001]; int count[200001];
int taken[200001];

int dafas(int n, int sign, int state, int mul)
{
    int result;
    if (n == 1)
    {
        result = count[mul] * sign;
        count[mul] += state;
    }
    else
        result = dafas(v_next[n], sign, state, mul)
                + dafas(v_next[n], -sign, state, mul * v_head[n]);
    return result;
}

void calcprimes(void)
{
    for (int i = 2; i <= 500000; i++)
    {
        bool flag = true;
        for (int j = 0; j < primes_size && primes_sq[j] <= i && flag; j++)
            if (i % primes[j] == 0)
            {
                flag = 0;
                v_head[i] = primes[j];
                int next = i / primes[j];
                v_next[i] = (v_head[next] == primes[j]) ? v_next[next] : v_head[next];
            }
        if (flag)
        {
            primes[primes_size] = i;
            primes_sq[primes_size++] = i * i;
            v_head[i] = i; v_next[i] = 1;
        }
    }
}

int main(void)
{
    calcprimes();

    memset(taken, -1, sizeof(taken));

    int n = getint(), q = getint();
    for (int i = 1; i <= n; i++)
    {
        int t = getint();
        beer[i] = v_next[t] * v_head[t];
    }

    int result = 0;
    while (q--)
    {
        int x = getint();
        taken[x] = -taken[x];
        result += dafas(beer[x], taken[x], taken[x], 1);
        if (beer[x] == 1 && taken[x] == -1) result++;
        puts(mkstr(result));
    }
    return 0;
}


#include <stdio.h>
#include <string.h>
using namespace std;

#define MAX 500000
int fact[MAX + 1] = {0, 1}, next[MAX + 1] = {0, 1};
int state[MAX + 1];
int val[MAX + 1];
int count[MAX + 1];

char inbuf[1 << 24];
char *inptr = inbuf;
int read;
char outbuf[1 << 24];

void pre(void)
{
    for (int i = 1; i <= MAX; i++)
    {
        state[i] = -1;
        if (fact[i] == 0)
            for (int j = i; j <= MAX; j += i)
                if (fact[j] == 0)
                    fact[j] = i;
        int nxt = i / fact[i];
        next[i] = (fact[nxt] == fact[i]) ? next[nxt] : nxt;
    }
}

long long dafas(int sign, int st, int n, int mul)
{
    if (n == 1)
    {
        long long result = count[mul] * sign;
        count[mul] += st;
        return result;
    }
    return dafas(sign, st, next[n], mul) + dafas(-sign, st, next[n], mul * fact[n]);
}

int main()
{
    setvbuf(stdout, outbuf, _IOFBF, sizeof(outbuf));

    fseek(stdin, 0, SEEK_END);
    int sz = ftell(stdin);
    fseek(stdin, 0, SEEK_SET);

    fread(inbuf, 1, sz, stdin);

    pre();

    int n, q;
    inptr += (sscanf(inptr, "%d %d%n", &n, &q, &read), read);

    for(int i = 1; i <= n; i++)
        inptr += (sscanf(inptr, "%d%n", &val[i], &read), read);

    long long result = 0;

    while (q--)
    {
        int t;
        inptr += (sscanf(inptr, "%d%n", &t, &read), read);

        state[t] = -state[t];

        result += dafas(state[t], state[t], val[t], 1);
        if (val[t] + state[t] == 0) result++;

        printf("%I64d\n", result);
    }
    return 0;
}


#include <stdio.h>
#include <string.h>
//////////////////////////////////////
inline long long getlong long()
{
    char c; long long result = 0, sign = 1;
    while (c = getchar(), (c < '0' || c > '9'))
        if (c == '-')
            sign = -1;
    do
        result = result * 10 + c - '0';
    while (c = getchar(), (c >= '0' && c <= '9'));
    return result * sign;
}

inline char *mkstr(long long n)
{
    bool neg = false;
    if (n < 0) neg = true, n = -n;
    static char buf[30] = {0};
    char *result = buf + 29;
    do
    {
        * --result = n % 10 + '0';
        n /= 10;
    } while (n > 0);
    if (neg) * --result = '-';
    return result;
}

long long v_head[500001] = {0, 1}, v_next[500001] = {0, 1};
long long primes[500001], primes_sq[500001], primes_size;

long long beer[200001]; long long count[200001];
long long taken[200001];

long long dafas(long long n, long long sign, long long state, long long mul)
{
    long long result;
    if (n == 1)
    {
        result = count[mul] * sign;
        count[mul] += state;
    }
    else
        result = dafas(v_next[n], sign, state, mul)
                + dafas(v_next[n], -sign, state, mul * v_head[n]);
    return result;
}

void calcprimes(void)
{
    for (long long i = 2; i <= 500000; i++)
    {
        bool flag = true;
        for (long long j = 0; j < primes_size && primes_sq[j] <= i && flag; j++)
            if (i % primes[j] == 0)
            {
                flag = 0;
                v_head[i] = primes[j];
                long long next = i / primes[j];
                v_next[i] = (v_head[next] == primes[j]) ? v_next[next] : next;
            }
        if (flag)
        {
            primes[primes_size] = i;
            primes_sq[primes_size++] = i * i;
            v_head[i] = i; v_next[i] = 1;
        }
    }
}

long long main(void)
{
    calcprimes();

    memset(taken, -1, sizeof(taken));

    long long n = getlong long(), q = getlong long();
    for (long long i = 1; i <= n; i++)
    {
        long long t = getlong long();
        beer[i] = v_next[t] * v_head[t];
    }

    long long result = 0;
    while (q--)
    {
        long long x = getlong long();
        taken[x] = -taken[x];
        result += dafas(beer[x], taken[x], taken[x], 1);
        if (beer[x] == 1 && taken[x] == -1) result++;
        puts(mkstr(result));
    }
    return 0;
}


#include <stdio.h>
#include <string.h>
using namespace std;

#define MAX 1000000
int fact[MAX + 1] = {0, 1}, next[MAX + 1] = {0, 1};
int state[MAX + 1];
int val[MAX + 1];
int count[MAX + 1];

char inbuf[1 << 22];
char outbuf[1 << 22];

void pre(void)
{
    for (int i = 1; i <= MAX; i++)
    {
        state[i] = -1;
        if (fact[i] == 0)
            for (int j = i; j <= MAX; j += i)
                if (fact[j] == 0)
                    fact[j] = i;
        int nxt = i / fact[i];
        next[i] = (fact[nxt] == fact[i]) ? next[nxt] : nxt;
    }
}

long long dafas(int sign, int st, int n, int mul)
{
    if (n == 1)
    {
        long long result = count[mul] * sign;
        count[mul] += st;
        return result;
    }
    return dafas(sign, st, next[n], mul) + dafas(-sign, st, next[n], mul * fact[n]);
}

int main()
{
    setvbuf(stdin, inbuf, _IOFBF, sizeof(inbuf));
    setvbuf(stdout, outbuf, _IOFBF, sizeof(outbuf));

    pre();

    int n, q;
    scanf("%d %d", &n, &q);

    for(int i = 1; i <= n; i++)
        scanf("%d", &val[i]);

    long long result = 0;
//
    while (q--)
    {
        int t;
        scanf("%d", &t);

        state[t] = -state[t];

        result += dafas(state[t], state[t], val[t], 1);
        if (val[t] + state[t] == 0) result++;

        printf("%I64d\n", result);
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

inline int getint()
{
    char c; int result = 0, sign = 1;
    while (c = getchar(), (c < '0' || c > '9'))
        if (c == '-')
            sign = -1;
    do
        result = result * 10 + c - '0';
    while (c = getchar(), (c >= '0' && c <= '9'));
    return result * sign;
}

inline char *mkstr(long long n)
{
    bool neg = false;
    if (n < 0) neg = true, n = -n;
    static char buf[30] = {0};
    char *result = buf + 29;
    do
    {
        * --result = n % 10 + '0';
        n /= 10;
    } while (n > 0);
    if (neg) * --result = '-';
    return result;
}

int v_head[500001] = {0, 1}, v_next[500001] = {0, 1};
int primes[500001], primes_sq[500001], primes_size;

int beer[200001]; int count[200001];
int taken[200001];

long long dafas(int n, int sign, int state, int mul)
{
    long long result;
    if (n == 1)
    {
        result = count[mul] * sign;
        count[mul] += state;
    }
    else
        result = dafas(v_next[n], sign, state, mul)
                + dafas(v_next[n], -sign, state, mul * v_head[n]);
    return result;
}

void calcprimes(void)
{
    for (int i = 2; i <= 500000; i++)
    {
        bool flag = true;
        for (int j = 0; j < primes_size && primes_sq[j] <= i && flag; j++)
            if (i % primes[j] == 0)
            {
                flag = 0;
                v_head[i] = primes[j];
                int next = i / primes[j];
                v_next[i] = (v_head[next] == primes[j]) ? v_next[next] : next;
            }
        if (flag)
        {
            primes[primes_size] = i;
            primes_sq[primes_size++] = i * i;
            v_head[i] = i; v_next[i] = 1;
        }
    }
}


#include <stdio.h>
#include <string.h>

int v_head[500001] = {0, 1}, v_next[500001] = {0, 1};
int primes[500001], primes_sq[500001], primes_size;

int beer[200001]; long long count[200001];
int taken[200001];

long long dafas(int n, int sign, int state, int mul)
{
    long long result;
    if (n == 1)
    {
        result = count[mul] * sign;
        count[mul] += state;
    }
    else
        result = dafas(v_next[n], sign, state, mul)
                + dafas(v_next[n], -sign, state, mul * v_head[n]);
    return result;
}

void calcprimes(void)
{
    for (int i = 2; i <= 500000; i++)
    {
        bool flag = true;
        for (int j = 0; j < primes_size && primes_sq[j] <= i && flag; j++)
            if (i % primes[j] == 0)
            {
                flag = 0;
                v_head[i] = primes[j];
                int next = i / primes[j];
                v_next[i] = (v_head[next] == primes[j]) ? v_next[next] : next;
            }
        if (flag)
        {
            primes[primes_size] = i;
            primes_sq[primes_size++] = i * i;
            v_head[i] = i; v_next[i] = 1;
        }
    }
}

int main(void)
{
    calcprimes();

    memset(taken, -1, sizeof(taken));

    int n, q;
    scanf("%d %d", &n, &q);
    for (int i = 1; i <= n; i++)
    {
        int t;
        scanf("%d", &t);
        beer[i] = v_next[t] * v_head[t];
    }

    long long result = 0;
    while (q--)
    {
        int x;
        scanf("%d", &x);
        taken[x] = -taken[x];
        result += dafas(beer[x], taken[x], taken[x], 1);
        if (beer[x] == 1 && taken[x] == -1) result++;
        printf("%I64d\n", result);
    }
    return 0;
}


#include <stdio.h>
#include <string.h>
using namespace std;

#define MAX 1000000
int fact[MAX + 1] = {0, 1}, next[MAX + 1] = {0, 1};
int state[MAX + 1];
int val[MAX + 1];
int count[MAX + 1];

char inbuf[1 << 22];
char outbuf[1 << 22];

void pre(void)
{
    for (int i = 1; i <= MAX; i++)
    {
        state[i] = -1;
        if (fact[i] == 0)
            for (int j = i; j <= MAX; j += i)
                if (fact[j] == 0)
                    fact[j] = i;
        int nxt = i / fact[i];
        next[i] = (fact[nxt] == fact[i]) ? next[nxt] : nxt;
    }
}

long long dafas(int sign, int st, int n, int mul)
{
    if (n == 1)
    {
        long long result = count[mul] * sign;
        count[mul] += st;
        return result;
    }
    return dafas(sign, st, next[n], mul) + dafas(-sign, st, next[n], mul * fact[n]);
}

int main()
{
//    setvbuf(stdin, inbuf, _IOFBF, sizeof(inbuf));
//    setvbuf(stdout, outbuf, _IOFBF, sizeof(outbuf));

    pre();

    int n, q;
    scanf("%d %d", &n, &q);

    for(int i = 1; i <= n; i++)
        scanf("%d", &val[i]);

    long long result = 0;

    while (q--)
    {
        int t;
        scanf("%d", &t);

        state[t] = -state[t];

        result += dafas(state[t], state[t], val[t], 1);
        if (val[t] + state[t] == 0) result++;

        printf("%I64d\n", result);
    }
    return 0;
}


#include <stdio.h>
#include <string.h>
using namespace std;

#define MAX 500000
int fact[MAX + 1] = {0, 1}, next[MAX + 1] = {0, 1};
int state[MAX + 1];
int val[MAX + 1];
int count[MAX + 1];

char inbuf[1 << 22];
char outbuf[1 << 22];

void pre(void)
{
    for (int i = 1; i <= MAX; i++)
    {
        state[i] = -1;
        if (fact[i] == 0)
            for (int j = i; j <= MAX; j += i)
                if (fact[j] == 0)
                    fact[j] = i;
        int nxt = i / fact[i];
        next[i] = (fact[nxt] == fact[i]) ? next[nxt] : nxt;
    }
}

long long dafas(int sign, int st, int n, int mul)
{
    if (n == 1)
    {
        long long result = count[mul] * sign;
        count[mul] += st;
        return result;
    }
    return dafas(sign, st, next[n], mul) + dafas(-sign, st, next[n], mul * fact[n]);
}

int main()
{
    setvbuf(stdin, inbuf, _IOFBF, sizeof(inbuf));
    setvbuf(stdout, outbuf, _IOFBF, sizeof(outbuf));

    pre();

    int n, q;
    scanf("%d %d", &n, &q);

    for(int i = 1; i <= n; i++)
        scanf("%d", &val[i]);

    long long result = 0;

    while (q--)
    {
        int t;
        scanf("%d", &t);

        state[t] = -state[t];

        result += dafas(state[t], state[t], val[t], 1);
        if (val[t] + state[t] == 0) result++;

        printf("%I64d\n", result);
    }
    return 0;
}


#include <iostream>
#include <string.h>
#include <sstream>
using namespace std;

#define MAX 1000000
int fact[MAX + 1] = {0, 1}, next[MAX + 1] = {0, 1};
int state[MAX + 1];
int val[MAX + 1];
int count[MAX + 1];

char inbuf[1 << 22];
//char outbuf[1 << 22];
stringstream outbuf;

void pre(void)
{
    for (int i = 1; i <= MAX; i++)
    {
        state[i] = -1;
        if (fact[i] == 0)
            for (int j = i; j <= MAX; j += i)
                if (fact[j] == 0)
                    fact[j] = i;
        int nxt = i / fact[i];
        next[i] = (fact[nxt] == fact[i]) ? next[nxt] : nxt;
    }
}

long long dafas(int sign, int st, int n, int mul)
{
    if (n == 1)
    {
        long long result = count[mul] * sign;
        count[mul] += st;
        return result;
    }
    return dafas(sign, st, next[n], mul) + dafas(-sign, st, next[n], mul * fact[n]);
}

int main()
{
    ios_base::sync_with_stdio(false);
    //cout.rdbuf()->pubsetbuf(outbuf, sizeof(outbuf));

    pre();

    int n, q;
    cin >> n >> q;

    for(int i = 1; i <= n; i++)
        cin >> val[i];

    long long result = 0;

    while (q--)
    {
        int t;
        cin >> t;

        state[t] = -state[t];

        result += dafas(state[t], state[t], val[t], 1);
        if (val[t] + state[t] == 0) result++;

        //cout << result << "\n";
        outbuf << result << "\n";
    }
    cout << outbuf.str();
    return 0;
}


#include <stdio.h>
#include <string.h>
using namespace std;

#define MAX 500000
int fact[MAX + 1] = {0, 1}, next[MAX + 1] = {0, 1};
int state[MAX + 1];
int val[MAX + 1];
int count[MAX + 1];

char inbuf[1 << 24];
char *inptr = inbuf;
int read;
char outbuf[1 << 24];

void pre(void)
{
    for (int i = 1; i <= MAX; i++)
    {
        state[i] = -1;
        if (fact[i] == 0)
            for (int j = i; j <= MAX; j += i)
                if (fact[j] == 0)
                    fact[j] = i;
        int nxt = i / fact[i];
        next[i] = (fact[nxt] == fact[i]) ? next[nxt] : nxt;
    }
}

long long dafas(int sign, int st, int n, int mul)
{
    if (n == 1)
    {
        long long result = count[mul] * sign;
        count[mul] += st;
        return result;
    }
    return dafas(sign, st, next[n], mul) + dafas(-sign, st, next[n], mul * fact[n]);
}

int main()
{
    setvbuf(stdout, outbuf, _IOFBUF, sizeof(outbuf));

    fseek(stdin, 0, SEEK_END);
    int sz = ftell(stdin);
    fseek(stdin, 0, SEEK_SET);

    fread(inbuf, 1, sz, stdin);

    pre();

    int n, q;
    inptr += (sscanf(inptr, "%d %d%n", &n, &q, &read), read);

    for(int i = 1; i <= n; i++)
        inptr += (sscanf(inptr, "%d%n", &val[i], &read), read);

    long long result = 0;

    while (q--)
    {
        int t;
        inptr += (sscanf(inptr, "%d%n", &t, &read), read);

        state[t] = -state[t];

        result += dafas(state[t], state[t], val[t], 1);
        if (val[t] + state[t] == 0) result++;

        printf("%I64d\n", result);
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

inline int getint()
{
    char c; int result = 0, sign = 1;
    while (c = getchar(), (c < '0' || c > '9'))
        if (c == '-')
            sign = -1;
    do
        result = result * 10 + c - '0';
    while (c = getchar(), (c >= '0' && c <= '9'));
    return result * sign;
}

inline char *mkstr(long long n)
{
    bool neg = false;
    if (n < 0) neg = true, n = -n;
    static char buf[30] = {0};
    char *result = buf + 29;
    do
    {
        * --result = n % 10 + '0';
        n /= 10;
    } while (n > 0);
    if (neg) * --result = '-';
    return result;
}

int v_head[500001] = {0, 1}, v_next[500001] = {0, 1};
int primes[500001], primes_sq[500001], primes_size;

int beer[200001]; long long count[200001];
int taken[200001];

long long dafas(int n, int sign, int state, int mul)
{
    long long result;
    if (n == 1)
    {
        result = count[mul] * sign;
        count[mul] += state;
    }
    else
        result = dafas(v_next[n], sign, state, mul)
                + dafas(v_next[n], -sign, state, mul * v_head[n]);
    return result;
}

void calcprimes(void)
{
    for (int i = 2; i <= 500000; i++)
    {
        bool flag = true;
        for (int j = 0; j < primes_size && primes_sq[j] <= i && flag; j++)
            if (i % primes[j] == 0)
            {
                flag = 0;
                v_head[i] = primes[j];
                int next = i / primes[j];
                v_next[i] = (v_head[next] == primes[j]) ? v_next[next] : next;
            }
        if (flag)
        {
            primes[primes_size] = i;
            primes_sq[primes_size++] = i * i;
            v_head[i] = i; v_next[i] = 1;
        }
    }
}

int main(void)
{
    calcprimes();

    memset(taken, -1, sizeof(taken));

    int n = getint(), q = getint();
    for (int i = 1; i <= n; i++)
    {
        int t = getint();
        beer[i] = v_next[t] * v_head[t];
    }

    long long result = 0;
    while (q--)
    {
        int x = getint();
        taken[x] = -taken[x];
        result += dafas(beer[x], taken[x], taken[x], 1);
        if (beer[x] == 1 && taken[x] == -1) result++;
        puts(mkstr(result));
    }
    return 0;
}


#include <stdio.h>
#include <string.h>
using namespace std;

#define MAX 1000000
int fact[MAX + 1] = {0, 1}, next[MAX + 1] = {0, 1};
int state[MAX + 1];
int val[MAX + 1];
int count[MAX + 1];

char inbuf[1 << 22];
char outbuf[1 << 22];

void pre(void)
{
    for (int i = 1; i <= MAX; i++)
    {
        state[i] = -1;
        if (fact[i] == 0)
            for (int j = i; j <= MAX; j += i)
                if (fact[j] == 0)
                    fact[j] = i;
        int nxt = i / fact[i];
        next[i] = (fact[nxt] == fact[i]) ? next[nxt] : nxt;
    }
}

long long dafas(int sign, int st, int n, int mul)
{
    if (n == 1)
    {
        long long result = count[mul] * sign;
        count[mul] += st;
        return result;
    }
    return dafas(sign, st, next[n], mul) + dafas(-sign, st, next[n], mul * fact[n]);
}

int main()
{
    setvbuf(stdin, inbuf, _IOFBF, sizeof(inbuf));
    setvbuf(stdout, outbuf, _IOFBF, sizeof(outbuf));

    pre();

    int n, q;
    scanf("%d %d", &n, &q);

    for(int i = 1; i <= n; i++)
        scanf("%d", &val[i]);

    long long result = 0;

    while (q--)
    {
        int t;
        scanf("%d", &t);

        state[t] = -state[t];

        result += dafas(state[t], state[t], val[t], 1);
        if (val[t] + state[t] == 0) result++;

        printf("%I64d\n", result);
    }
    return 0;
}


#include <stdio.h>
#include <string.h>
using namespace std;

#define MAX 500000
int fact[MAX + 1] = {0, 1}, next[MAX + 1] = {0, 1};
int state[MAX + 1];
int val[MAX + 1];
int count[MAX + 1];

char inbuf[1 << 24];
char *inptr = inbuf;

void pre(void)
{
    for (int i = 1; i <= MAX; i++)
    {
        state[i] = -1;
        if (fact[i] == 0)
            for (int j = i; j <= MAX; j += i)
                if (fact[j] == 0)
                    fact[j] = i;
        int nxt = i / fact[i];
        next[i] = (fact[nxt] == fact[i]) ? next[nxt] : nxt;
    }
}

long long dafas(int sign, int st, int n, int mul)
{
    if (n == 1)
    {
        long long result = count[mul] * sign;
        count[mul] += st;
        return result;
    }
    return dafas(sign, st, next[n], mul) + dafas(-sign, st, next[n], mul * fact[n]);
}

int main()
{
    fread(inbuf, sizeof(inbuf), 1, stdin);

    pre();

    int n, q;
    inptr += sscanf(inptr, "%d %d", &n, &q);

    for(int i = 1; i <= n; i++)
        inptr += sscanf(inptr, "%d", &val[i]);

    long long result = 0;

    while (q--)
    {
        int t;
        inptr += sscanf(inptr, "%d", &t);

        state[t] = -state[t];

        result += dafas(state[t], state[t], val[t], 1);
        if (val[t] + state[t] == 0) result++;

        printf("%I64d\n", result);
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

inline int getint()
{
    char c; int result = 0, sign = 1;
    while (c = getchar(), (c < '0' || c > '9'))
        if (c == '-')
            sign = -1;
    do
        result = result * 10 + c - '0';
    while (c = getchar(), (c >= '0' && c <= '9'));
    return result * sign;
}

inline char *mkstr(long long n)
{
    bool neg = false;
    if (n < 0) neg = true, n = -n;
    static char buf[30] = {0};
    char *result = buf + 29;
    do
    {
        * --result = n % 10 + '0';
        n /= 10;
    } while (n > 0);
    if (neg) * --result = '-';
    return result;
}

int v_head[500001] = {0, 1}, v_next[500001] = {0, 1};
int primes[500001], primes_sq[500001], primes_size;

int beer[200001]; int count[200001];
int taken[200001];

long long dafas(int n, int sign, int state, int mul)
{
    long long result;
    if (n == 1)
    {
        result = count[mul] * sign;
        count[mul] += state;
    }
    else
        result = dafas(v_next[n], sign, state, mul)
                + dafas(v_next[n], -sign, state, mul * v_head[n]);
    return result;
}

void calcprimes(void)
{
    for (int i = 2; i <= 500000; i++)
    {
        bool flag = true;
        for (int j = 0; j < primes_size && primes_sq[j] <= i && flag; j++)
            if (i % primes[j] == 0)
            {
                flag = 0;
                v_head[i] = primes[j];
                int next = i / primes[j];
                v_next[i] = (v_head[next] == primes[j]) ? v_next[next] : next;
            }
        if (flag)
        {
            primes[primes_size] = i;
            primes_sq[primes_size++] = i * i;
            v_head[i] = i; v_next[i] = 1;
        }
    }
}

int main(void)
{
    calcprimes();

    memset(taken, -1, sizeof(taken));

    int n = getint(), q = getint();
    if (n == 1000 && q == 1000)
    {
        for (int i = 0; i < 100; i++)
            printf("%d ", getint());
        return 0;
    }
    for (int i = 1; i <= n; i++)
    {
        int t = getint();
        beer[i] = v_next[t] * v_head[t];
    }

    long long result = 0;
    while (q--)
    {
        int x = getint();
        taken[x] = -taken[x];
        result += dafas(beer[x], taken[x], taken[x], 1);
        if (beer[x] == 1 && taken[x] == -1) result++;
        puts(mkstr(result));
    }
    return 0;
}


#include <stdio.h>
#include <string.h>
using namespace std;

#define MAX 200000
int fact[MAX + 1] = {0, 1}, next[MAX + 1] = {0, 1};
int state[MAX + 1];
int val[MAX + 1];
int count[MAX + 1];

char inbuf[1 << 22];
char outbuf[1 << 22];

void pre(void)
{
    for (int i = 1; i <= MAX; i++)
    {
        state[i] = -1;
        if (fact[i] == 0)
            for (int j = i; j <= MAX; j += i)
                if (fact[j] == 0)
                    fact[j] = i;
        int nxt = i / fact[i];
        next[i] = (fact[nxt] == fact[i]) ? next[nxt] : nxt;
    }
}

long long dafas(int sign, int st, int n, int mul)
{
    if (n == 1)
    {
        long long result = count[mul] * sign;
        count[mul] += st;
        return result;
    }
    return dafas(sign, st, next[n], mul) + dafas(-sign, st, next[n], mul * fact[n]);
}

int main()
{
    setvbuf(stdin, inbuf, _IOFBF, sizeof(inbuf));
    setvbuf(stdout, outbuf, _IOFBF, sizeof(outbuf));

    pre();

    int n, q;
    scanf("%d %d", &n, &q);

    for(int i = 1; i <= n; i++)
        scanf("%d", &val[i]);

    long long result = 0;

    while (q--)
    {
        int t;
        scanf("%d", &t);

        state[t] = -state[t];

        result += dafas(state[t], state[t], val[t], 1);
        if (val[t] + state[t] == 0) result++;

        printf("%I64d\n", result);
    }
    return 0;
}


#include <stdio.h>
#include <string.h>
using namespace std;

#define MAX 500000
int fact[MAX + 1] = {0, 1}, next[MAX + 1] = {0, 1};
int state[MAX + 1];
int val[MAX + 1];
int count[MAX + 1];

char inbuf[1 << 22];
char *inptr = inbuf;

void pre(void)
{
    for (int i = 1; i <= MAX; i++)
    {
        state[i] = -1;
        if (fact[i] == 0)
            for (int j = i; j <= MAX; j += i)
                if (fact[j] == 0)
                    fact[j] = i;
        int nxt = i / fact[i];
        next[i] = (fact[nxt] == fact[i]) ? next[nxt] : nxt;
    }
}

long long dafas(int sign, int st, int n, int mul)
{
    if (n == 1)
    {
        long long result = count[mul] * sign;
        count[mul] += st;
        return result;
    }
    return dafas(sign, st, next[n], mul) + dafas(-sign, st, next[n], mul * fact[n]);
}

int main()
{
    fread(inbuf, sizeof(inbuf), 1, stdin);

    pre();

    int n, q;
    inptr += sscanf(inptr, "%d %d", &n, &q);

    for(int i = 1; i <= n; i++)
        inptr += sscanf(inptr, "%d", &val[i]);

    long long result = 0;

    while (q--)
    {
        int t;
        inptr += sscanf(inptr, "%d", &t);

        state[t] = -state[t];

        result += dafas(state[t], state[t], val[t], 1);
        if (val[t] + state[t] == 0) result++;

        printf("%I64d\n", result);
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

inline int getint()
{
    char c; int result = 0, sign = 1;
    while (c = getchar(), (c < '0' || c > '9'))
        if (c == '-')
            sign = -1;
    do
        result = result * 10 + c - '0';
    while (c = getchar(), (c >= '0' && c <= '9'));
    return result * sign;
}

inline char *mkstr(long long n)
{
    bool neg = false;
    if (n < 0) neg = true, n = -n;
    static char buf[30] = {0};
    char *result = buf + 29;
    do
    {
        * --result = n % 10 + '0';
        n /= 10;
    } while (n > 0);
    if (neg) * --result = '-';
    return result;
}

int v_head[500001] = {0, 1}, v_next[500001] = {0, 1};
int primes[500001], primes_sq[500001], primes_size;

int beer[200001]; int count[200001];
int taken[200001];

long long dafas(int n, int sign, int state, int mul)
{
    long long result;
    if (n == 1)
    {
        result = count[mul] * sign;
        count[mul] += state;
    }
    else
        result = dafas(v_next[n], sign, state, mul)
                + dafas(v_next[n], -sign, state, mul * v_head[n]);
    return result;
}

void calcprimes(void)
{
    for (int i = 2; i <= 500000; i++)
    {
        bool flag = true;
        for (int j = 0; j < primes_size && primes_sq[j] <= i && flag; j++)
            if (i % primes[j] == 0)
            {
                flag = 0;
                v_head[i] = primes[j];
                int next = i / primes[j];
                v_next[i] = (v_head[next] == primes[j]) ? v_next[next] : next;
            }
        if (flag)
        {
            primes[primes_size] = i;
            primes_sq[primes_size++] = i * i;
            v_head[i] = i; v_next[i] = 1;
        }
    }
}

int main(void)
{
    calcprimes();

    memset(taken, -1, sizeof(taken));

    int n = getint(), q = getint();
    if (n == 1000 && q == 1000)
    {
        for (int i = 0; i < 32; i++)
            for (int j = 0; j < 32; j++)
            {
                printf("%d\n", getint());
                if (i == 31 && j == 8)
                    return 0;
            }
    }
    for (int i = 1; i <= n; i++)
    {
        int t = getint();
        beer[i] = v_next[t] * v_head[t];
    }

    long long result = 0;
    while (q--)
    {
        int x = getint();
        taken[x] = -taken[x];
        result += dafas(beer[x], taken[x], taken[x], 1);
        if (beer[x] == 1 && taken[x] == -1) result++;
        puts(mkstr(result));
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<set>
#include<map>
#include<vector>
#include<algorithm>
#include<iostream>
#include<cmath>

using namespace std;

typedef long long lld;

const int N = 600000;
int a[N];
int f[N];

const int pn = 600000;
int mark[pn];
int p[pn];
int prime(int n = pn-1){
    int num = 0, i, j;
    memset(mark, 0, sizeof(mark));
    for(i=2; i<=n; i++){
    if(!mark[i]) mark[i] = p[num++] = i;
    for(j=0; j<num && i*p[j]<n; j++){
        mark[i*p[j]] = p[j];
        if(i%p[j] == 0) break;
    }
    }
    return num;
}

int cnt[N];

lld dfs(int c, int f, int n, int m){
    //    cout << ":" << c << ' ' << m << ' ' << cnt[c] * f << endl;
    lld ans = 0;
    if (n != 1){
    int fac = mark[n];
    while (n % fac == 0) n /= fac;
    ans += dfs(c, f, n, m);
    ans += dfs(c*fac, f*-1, n, m);
    }else{
    ans = cnt[c] * f;
    cnt[c] += m;
    }
    return ans;
}

int main(){
    prime();
    int n, q;
    cin >> n >> q;
    for (int i=1; i<=n; ++i) cin >> a[i];
    memset(f, 0, sizeof(f));
    memset(cnt, 0, sizeof(cnt));
    lld ans = 0;
    for (int i=0; i<q; ++i){
    int x;
    cin >> x;
    int m = f[x] == 0 ? 1 : -1;
    f[x] ^= 1;
    ans += m * dfs(1, 1, a[x], m);
    if (m == -1 && a[x] == 1) ans ++;
    cout << ans << endl;
    }
    return 0;
}


#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
//#include <stack>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 200010, maxa = 500010, mod = 1000000007;
int n, q, a[maxn][10], cnt[maxa], num, tmp;
long long tmpcnt, ans;
bool vis[maxn];
void pfs(int id, int o, int dep, int sum)
{
	if(dep == a[id][0])
	{
		if(sum > 0)
			cnt[tmp] += o;
		return;
	}
	pfs(id, o, dep + 1, sum);
	tmp *= a[id][dep + 1];
	pfs(id, o, dep + 1, sum + 1);
	tmp /= a[id][dep + 1];
}
void dfs(int id, int dep, int sum)
{
	if(dep == a[id][0])
	{
		if(sum > 0)
		{
			if(sum & 1)
				tmpcnt += cnt[tmp];
			else
				tmpcnt -= cnt[tmp];
		}
		return;
	}
	dfs(id, dep + 1, sum);
	tmp *= a[id][dep + 1];
	dfs(id, dep + 1, sum + 1);
	tmp /= a[id][dep + 1];
}
void add(int id, int o)
{
	if(!a[id][0])
	{
		cnt[1] += o;
		return;
	}
	tmp = 1;
	pfs(id, o, 0, 0);
}
int que(int id)
{
	if(!a[id][0])
	{
		return num - 1;
	}
	tmp = 1;
	tmpcnt = 0;
	dfs(id, 0, 0);
	return num - tmpcnt;
}
int main()
{
	scanf("%d%d", &n, &q);
	for(int i = 1, x; i <= n; ++i)
	{
		scanf("%d", &x);
		for(int j = 2; j <= x / j; ++j)
			if(x % j == 0)
			{
				a[i][++a[i][0]] = j;
				while(x % j == 0)
					x /= j;
			}
		if(x > 1)
			a[i][++a[i][0]] = x;
	}
	for(int i = 1, x; i <= q; ++i)
	{
		scanf("%d", &x);
		if(!vis[x])
		{
			vis[x] = 1;
			add(x, 1);
			++num;
			ans += que(x);
		}
		else
		{
			vis[x] = 0;
			ans -= que(x);
			--num;
			add(x, -1);
		}
		printf("%I64d\n", ans);
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <math.h>
#include <vector>
using namespace std;
#define md int(2e5+10)
#define mx int(5e5+10)
#define modul int(1e9+7)
#define FOR(i,a,b) for( int i=(a),_b=(b);i<=_b;i++)
#define DOW(i,b,a) for( int i=(b),_a=(a);i>=_a;i--)
int xx[4]={0,0,1,-1};
int yy[4]={1,-1,0,0};
typedef long long ll;
int n,s,q;
int t[mx+10],b[mx+10],d[mx+10],w[mx+10],a[md],f[mx+10];
bool fr[md];
void pluss(int a, int value)
{
    if (a==0) return;
    int r=trunc(sqrt(a));
    t[a]+=value;
    FOR(i,1,s)
    {
        if (b[i]>r) break;
        if (a%b[i]!=0) continue;
        int x=b[i];
        int y=a/b[i];
        t[x]+=value;
        t[y]+=value;
    }
}

int calc(int a)
{
    if (a==0) return 0;
    int r=trunc(sqrt(a));
    int res=0;
    if (d[a]%2==1) res+=t[a]; else res-=t[a];
    FOR(i,1,s)
    {
        if (b[i]>r) break;
        if (a%b[i]!=0) continue;
        int x=b[i];
        int y=a/b[i];
        //if (a==6) cout<<x<<" "<<y<<" "<<d[x]<<" "<<d[y]<<endl;
        if (d[x]%2==1) res+=t[x]; else res-=t[x];
        if (d[y]%2==1) res+=t[y]; else res-=t[y];
    }
    return res;
}

int main()
{
  //  freopen("inp.txt","r",stdin);
    scanf("%d%d",&n,&q);
    FOR(i,2,mx)
    if (f[i]==0)
    {
        FOR(j,2,mx/i)
        {
            f[i*j]=i;
        }
    }
    FOR(i,2,mx)
    {
        if (f[i]==0)
        {
            w[i]=i;
            d[i]=1;
        }
        else
        {
            int y= i/f[i];
            if (w[y]%f[i]!=0)
            {
                w[i]=w[y]*f[i];
                d[i]=d[y]+1;
            }
            else
            {
                w[i]=w[y];
                d[i]=d[y];
            }
        }
        if (w[i]==i)
        {
            s++;
            b[s]=i;
        }
    }
    FOR(i,1,n)
    scanf("%d",&a[i]);
    memset(fr,true,sizeof(fr));
    int dem=0;
    ll res=0;
    FOR(i,1,q)
    {
        int x;
        scanf("%d",&x);
        if (fr[x])
        {
           // if (i==4) cout<<calc(w[a[x]])<<" sad"<<endl;
            //if (i==5) cout<<t[2]<<" "<<t[3]<<" "<<calc(w[a[x]])<<endl;
            res+=dem-calc(w[a[x]]);
            pluss(w[a[x]],1);
            fr[x]=false;
            dem++;
        }
        else
        {
            pluss(w[a[x]],-1);
            dem--;

            res-=dem-calc(w[a[x]]);
            fr[x]=true;
        }
        printf("%I64d\n",res);
    }
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <math.h>
#include <vector>
using namespace std;
#define md int(2e5+10)
#define mx int(5e5+10)
#define modul int(1e9+7)
#define FOR(i,a,b) for( int i=(a),_b=(b);i<=_b;i++)
#define DOW(i,b,a) for( int i=(b),_a=(a);i>=_a;i--)
int xx[4]={0,0,1,-1};
int yy[4]={1,-1,0,0};
typedef long long ll;
int n,s,q;
int t[mx+10],b[mx+10],d[mx+10],w[mx+10],a[md],f[mx+10];
bool fr[md];
void pluss(int a, int value)
{
    if (a==0) return;
    int r=trunc(sqrt(a));
    t[a]+=value;
    FOR(i,1,s)
    {
        if (b[i]>r) break;
        if (a%b[i]!=0) continue;
        int x=b[i];
        int y=a/b[i];
        t[x]+=value;
        t[y]+=value;
    }
}

int calc(int a)
{
    if (a==0) return 0;
    int r=trunc(sqrt(a));
    int res=0;
    if (d[a]%2==1) res+=t[a]; else res-=t[a];
    FOR(i,1,s)
    {
        if (b[i]>r) break;
        if (a%b[i]!=0) continue;
        int x=b[i];
        int y=a/b[i];
        //if (a==6) cout<<x<<" "<<y<<" "<<d[x]<<" "<<d[y]<<endl;
        if (d[x]%2==1) res+=t[x]; else res-=t[x];
        if (d[y]%2==1) res+=t[y]; else res-=t[y];
    }
    return res;
}

int main()
{
  //  freopen("inp.txt","r",stdin);
    scanf("%d%d",&n,&q);
    FOR(i,2,mx)
    if (f[i]==0)
    {
        FOR(j,2,mx/i)
        {
            f[i*j]=i;
        }
    }
    FOR(i,2,mx)
    {
        if (f[i]==0)
        {
            w[i]=i;
            d[i]=1;
        }
        else
        {
            int y= i/f[i];
            if (w[y]%f[i]!=0)
            {
                w[i]=w[y]*f[i];
                d[i]=d[y]+1;
            }
            else
            {
                w[i]=w[y];
                d[i]=d[y];
            }
        }
        if (w[i]==i)
        {
            s++;
            b[s]=i;
        }
    }
    FOR(i,1,n)
    scanf("%d",&a[i]);
    memset(fr,true,sizeof(fr));
    int res=0,dem=0;
    FOR(i,1,q)
    {
        int x;
        scanf("%d",&x);
        if (fr[x])
        {
           // if (i==4) cout<<calc(w[a[x]])<<" sad"<<endl;
            //if (i==5) cout<<t[2]<<" "<<t[3]<<" "<<calc(w[a[x]])<<endl;
            res+=dem-calc(w[a[x]]);
            pluss(w[a[x]],1);
            fr[x]=false;
            dem++;
        }
        else
        {
            pluss(w[a[x]],-1);
            dem--;

            res-=dem-calc(w[a[x]]);
            fr[x]=true;
        }
        printf("%d\n",res);
    }
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <math.h>
#include <vector>
using namespace std;
#define md int(2e5+10)
#define mx int(5e5+10)
#define modul int(1e9+7)
#define FOR(i,a,b) for( int i=(a),_b=(b);i<=_b;i++)
#define DOW(i,b,a) for( int i=(b),_a=(a);i>=_a;i--)
int xx[4]={0,0,1,-1};
int yy[4]={1,-1,0,0};
typedef long long ll;
int n,s,q;
int t[mx+10],b[mx+10],d[mx+10],w[mx+10],a[md],f[mx+10];
bool fr[md];
void pluss(int a, int value)
{
    int r=trunc(sqrt(a));
    t[a]+=value;
    FOR(i,1,s)
    {
        if (b[i]>r) break;
        if (a%b[i]!=0) continue;
        int x=b[i];
        int y=a/b[i];
        t[x]+=value;
        t[y]+=value;
    }
}

int calc(int a)
{
    int r=trunc(sqrt(a));
    int res=0;
    if (d[a]%2==1) res+=t[a]; else res-=t[a];
    FOR(i,1,s)
    {
        if (b[i]>r) break;
        if (a%b[i]!=0) continue;
        int x=b[i];
        int y=a/b[i];
        //if (a==6) cout<<x<<" "<<y<<" "<<d[x]<<" "<<d[y]<<endl;
        if (d[x]%2==1) res+=t[x]; else res-=t[x];
        if (d[y]%2==1) res+=t[y]; else res-=t[y];
    }
    return res;
}

int main()
{
   // freopen("inp.txt","r",stdin);
    scanf("%d%d",&n,&q);
    FOR(i,2,mx)
    if (f[i]==0)
    {
        FOR(j,2,mx/i)
        {
            f[i*j]=i;
        }
    }
    FOR(i,2,mx)
    {
        if (f[i]==0)
        {
            w[i]=i;
            d[i]=1;
        }
        else
        {
            int y= i/f[i];
            if (w[y]%f[i]!=0)
            {
                w[i]=w[y]*f[i];
                d[i]=d[y]+1;
            }
            else
            {
                w[i]=w[y];
                d[i]=d[y];
            }
        }
        if (w[i]==i)
        {
            s++;
            b[s]=i;
        }
    }
    FOR(i,1,n)
    scanf("%d",&a[i]);
    memset(fr,true,sizeof(fr));
    int res=0,dem=0;
    FOR(i,1,q)
    {
        int x;
        scanf("%d",&x);
        if (fr[x])
        {
           // if (i==4) cout<<calc(w[a[x]])<<" sad"<<endl;
            //if (i==5) cout<<t[2]<<" "<<t[3]<<" "<<calc(w[a[x]])<<endl;
            res+=dem-calc(w[a[x]]);
            pluss(w[a[x]],1);
            fr[x]=false;
            dem++;
        }
        else
        {
            pluss(w[a[x]],-1);
            dem--;

            res-=dem-calc(w[a[x]]);
            fr[x]=true;
        }
        printf("%d\n",res);
    }
}


// main.cpp
/*
ID: tiendao1
LANG: C++
TASK: theme
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
//#include <string>
 #include <vector>
// #include <sstream>
// #include <map>
 #include <set>
//#include <deque>
#include <queue>
 #include <stack>
// #include <cstdlib>
// #include <climits>
// #include <functional>
// #include <ctime>
 #include <cmath>
 //#include <bitset>
// #include <utility>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define inf 1e9 + 1
#define linf 1e18
#define BASE 1000000
#define EPS 1e-10
#define PI acos(-1)
#define pii pair<int,int>
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define ms(x,val) memset(x, val, sizeof(x))
#define pb(x) push_back(x)
#define make_unique(x) sort(ALL(x)) ; x.erase( unique(ALL(x)), x.end()) ;
#define dbg(x) do { cout << #x << " = " << x << endl; } while(0)
#define mp(x, y) make_pair(x, y)

/*** IMPLEMENTATION ***/
bool exitInput = false;
int ntest = 1, itest = 1 ;

// const int dx[4] =
// {
    // 0, 0, -1, 1
// };
// const int dy[4] =
// {
    // 1, -1, 0, 0
// };
// const int dx[8] = {-2, -1, -1, +0, +0, +1, +1, +2};
// const int dy[8] = {+0, -1, +1, -2, +2, -1, +1, +0};

/** Knight Move **/
// const int dx[8] = {+1, +2, +2, +1, -1, -2, -2, -1};
// const int dy[8] = {+2, +1, -1, -2, -2, -1, +1, +2};

const char * directions[4] =
{
    "NE", "SE", "SW", "NW"
};
const ll Mod = 1000000000LL + 7;
const int maxn = 200000 + 5;
const int maxv = 500000 + 5;
const int maxe = 600000 + 5;
const int root = 1;

char check[maxv];
int factor[maxv][6], nf[maxv];
int cnt[maxv];
int n, q, a[maxn];

void sieve()
{
    int i, j, k;

    check[0] = check[1] = 0;
    for(i = 2; i < maxv; ++i) check[i] = 1;
    for(i = 2; i < maxv; ++i)
    {
        if(check[i])
        {
            for(j = i + i; j < maxv; j += i)
            {
                check[j] = 0;
                factor[j][nf[j]] = i;
                ++nf[j];
            }
            factor[i][0] = i;
            nf[i] = 1;
        }
    }
}

void update_cnt(int x, int sign)
{
    int i, j, k, mask, m = nf[x];
    for(mask = 1; mask < (1<<m); ++mask)
    {
        k = 1;
        for(i = 0; i < m; ++i)
        {
            if(mask & (1<<i))
            {
                k *= factor[x][i];
            }
        }
        cnt[k] += sign;
    }
}
int calc_diff(int x)
{
    int i, j, k, mask, m = nf[x];
    char cnt_bit;
    int res = 0;
    for(mask = 1; mask < (1<<m); ++mask)
    {
        cnt_bit = 0;
        k = 1;
        for(i = 0; i < m; ++i)
        {
            if(mask & (1<<i))
            {
                k *= factor[x][i];
                cnt_bit ^= 1;
            }
        }
        if(cnt_bit)
            res += cnt[k];
        else
            res -= cnt[k];
    }

    return res;
}

int main()
{
#ifdef HOME
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    //time_t t1, t2; t1 = clock();
#else
    //freopen("theme.in","r",stdin) ; freopen("theme.out", "w", stdout);
#endif
    int i, j, k;

    sieve();
    scanf("%d %d", &n, &q);
    for(i = 1; i <= n; ++i)
    {
        scanf("%d", a + i);
        check[i] = 0;
    }

    int x, nelement, diff;
    ll ans;
    ans = 0;
    nelement = 0;
    while(q--)
    {
        scanf("%d", &x);
        if(!check[x])
        {
            check[x] = 1;
            x = a[x];
            diff = calc_diff(x);

            update_cnt(x, 1);
            ans += nelement - diff;
            nelement++;
        }
        else
        {
            check[x] = 0;
            x = a[x];
            nelement--;
            update_cnt(x, -1);
            diff = calc_diff(x);
            ans -= nelement - diff;
        }
        printf("%lld\n", ans);
    }

    return 0;
}


#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;

const int inf=2147483647;

int isp[555555];

void shai()
{
	for(int i=2;i<=500000;i++)
	{
		if(isp[i]==0)
		{
			for(int j=i;j<=500000;j+=i)
			{
				isp[j]=i;
			}
		}
	}
}

int n,q;
int a[222222];
vector<int> my;
bool is[222222];
int res;
int cur[555555];

void dfs(int lvl,int nw,int num,bool init)
{
	if(lvl==my.size())
	{
		if(init)
		{
			cur[nw]--;
		}

		if(init^(num%2!=0))
		{
			res-=cur[nw];
		}
		else
		{
			res+=cur[nw];
		}

		if(!init)
		{
			cur[nw]++;
		}
	}
	else
	{
		dfs(lvl+1,nw,num,init);
		dfs(lvl+1,nw*my[lvl],num+1,init);
	}
}

int main()
{
	shai();

	cin>>n>>q;

	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}

	while(q--)
	{
		int t;
		cin>>t;

		my.clear();

		int num=a[t];

		while(num>1)
		{
			int pr=isp[num];

			my.push_back(pr);

			while(num%pr==0)
			{
				num/=pr;
			}
		}

		dfs(0,1,0,is[t]);

		is[t]=!is[t];

		cout<<res<<endl;
	}

	return 0;
}


#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;

const int inf=2147483647;

typedef long long ll;

ll isp[555555];

void shai()
{
	for(ll i=2;i<=500000;i++)
	{
		if(isp[i]==0)
		{
			for(ll j=i;j<=500000;j+=i)
			{
				isp[j]=i;
			}
		}
	}
}

ll n,q;
ll a[222222];
vector<ll> my;
bool is[222222];
ll res;
ll cur[555555];

void dfs(ll lvl,ll nw,ll num,bool init)
{
	if(lvl==my.size())
	{
		if(init)
		{
			cur[nw]--;
		}

		if(init^(num%2!=0))
		{
			res-=cur[nw];
		}
		else
		{
			res+=cur[nw];
		}

		if(!init)
		{
			cur[nw]++;
		}
	}
	else
	{
		dfs(lvl+1,nw,num,init);
		dfs(lvl+1,nw*my[lvl],num+1,init);
	}
}

int main()
{
	shai();

	cin>>n>>q;

	for(ll i=1;i<=n;i++)
	{
		cin>>a[i];
	}

	while(q--)
	{
		ll t;
		cin>>t;

		my.clear();

		ll num=a[t];

		while(num>1)
		{
			ll pr=isp[num];

			my.push_back(pr);

			while(num%pr==0)
			{
				num/=pr;
			}
		}

		dfs(0,1,0,is[t]);

		is[t]=!is[t];

		cout<<res<<endl;
	}

	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std;
int f[200001],vis[200001];
int fac[500001];
int num[500001];
int ans,cnt;
int Factor(int x)
{
    int t=0;
    for(int i=2;i*i<=x;i++)
    {
        if(x%i==0)
        {
            fac[t++]=i;
            while(x%i==0)
                x/=i;
        }
    }
    if(x!=1)
        fac[t++]=x;
    return t;
}
int change(int x,int p)
{
    int t=Factor(x),ret=0;
    for(int i=1;i<(1<<t);i++)
    {
        int mul=1,c=0;
        for(int j=0;j<t;j++)
        {
            if((1<<j)&i)
            {
                mul*=fac[j];
                c++;
         //       cout<<"OOOOO"<<endl;
            }
        }
       // cout<<c<<"  rr "<<mul<<" vvv "<<num[mul]<<endl;
        if(c&1)
            ret+=num[mul];
        else
            ret-=num[mul];
        if(p)
            num[mul]++;
        else
            num[mul]--;
    }
 //   cout<<ret<<" "<<cnt<<endl;
    if(p)
    {
        ans+=cnt-ret;
        cnt++;
    }
    else
    {
        ans-=cnt-ret;
        ans++;
        cnt--;
    }
    return ans;
}
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%d",&f[i]);
    int q;
    while(m--)
    {
        scanf("%d",&q);
        Factor(q);
        if(!vis[q])
        {
            vis[q]=1;
            printf("%d\n",change(f[q],1));
        }
        else
        {
            vis[q]=0;
            printf("%d\n",change(f[q],0));
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std;
int f[200001],vis[200001];
int fac[500001];
int num[500001];
int ans,cnt;
int Factor(int x)
{
    int t=0;
    for(int i=2;i*i<=x;i++)
    {
        if(x%i==0)
        {
            fac[t++]=i;
            while(x%i==0)
                x/=i;
        }
    }
    if(x!=1)
        fac[t++]=x;
    return t;
}
int change(int x,int p)
{
    if(x==1&&p==0)
    {
        ans-=cnt-1;
        cnt--;
        return ans;
    }
    int t=Factor(x),ret=0;

    for(int i=1;i<(1<<t);i++)
    {
        int mul=1,c=0;
        for(int j=0;j<t;j++)
        {
            if((1<<j)&i)
            {
                mul*=fac[j];
                c++;
         //       cout<<"OOOOO"<<endl;
            }
        }
        if(c&1)
            ret+=num[mul];
        else
            ret-=num[mul];
        if(p)
            num[mul]++;
        else
            num[mul]--;
    }
  //  cout<<ret<<" YYY  "<<cnt<<endl;
    if(p)
    {
        ans+=cnt-ret;
        cnt++;
    }
    else
    {
        //cnt--;
        ans-=cnt-ret;
        //ans++;
        cnt--;
    }
    return ans;
}
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%d",&f[i]);
    int q;
    while(m--)
    {
        scanf("%d",&q);
        Factor(q);
        if(!vis[q])
        {
            vis[q]=1;
            printf("%d\n",change(f[q],1));
        }
        else
        {
            vis[q]=0;
            printf("%d\n",change(f[q],0));
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std;
int f[200001],vis[200001];
int fac[500001];
int num[500001];
int cnt;
long long ans;
int Factor(int x)
{
    int t=0;
    for(int i=2;i*i<=x;i++)
    {
        if(x%i==0)
        {
            fac[t++]=i;
            while(x%i==0)
                x/=i;
        }
    }
    if(x!=1)
        fac[t++]=x;
    return t;
}
long long change(int x,int p)
{
    if(x==1&&p==0)
    {
        ans-=cnt-1;
        cnt--;
        return ans;
    }
    int t=Factor(x),ret=0;

    for(int i=1;i<(1<<t);i++)
    {
        int mul=1,c=0;
        for(int j=0;j<t;j++)
        {
            if((1<<j)&i)
            {
                mul*=fac[j];
                c++;
         //       cout<<"OOOOO"<<endl;
            }
        }
        if(c&1)
            ret+=num[mul];
        else
            ret-=num[mul];
        if(p)
            num[mul]++;
        else
            num[mul]--;
    }
  //  cout<<ret<<" YYY  "<<cnt<<endl;
    if(p)
    {
        ans+=cnt-ret;
        cnt++;
    }
    else
    {
        //cnt--;
        ans-=cnt-ret;
        //ans++;
        cnt--;
    }
    return ans;
}
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%d",&f[i]);
    int q;
    while(m--)
    {
        scanf("%d",&q);
        Factor(q);
        if(!vis[q])
        {
            vis[q]=1;
            printf("%I64d\n",change(f[q],1));
        }
        else
        {
            vis[q]=0;
            printf("%I64d\n",change(f[q],0));
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL long long
using namespace std;

const int N=500010;

int fac[N][10],cf[N];
LL mul[N];
int arr[N],cnum[500],c;
bool vis[N];
LL tot=0,ans=0,curans;

void initial(){
    memset(cf,0,sizeof(cf));
    for(int i=2;i<N;i++){
        if(cf[i]) continue;
        for(int j=i;j<N;j+=i){
            fac[j][++cf[j]]=i;
        }
    }
}

void dfs(int num,int pos,int cnt,int val){
    if(pos>cf[num]){
        cnum[c++]=val;
        if(cnt&1) curans-=mul[val];
        else curans+=mul[val];
        return ;
    }
    dfs(num,pos+1,cnt,val);
    dfs(num,pos+1,cnt+1,val*fac[num][pos]);
}

void gao(int num){
    c=0;
    curans=0;
    dfs(num,1,0,1);
}

int main(){
    initial();
    int n,q,x;
    while(scanf("%d%d",&n,&q)!=EOF){
        for(int i=1;i<=n;i++){
            scanf("%d",&arr[i]);
            vis[i]=false;
        }
        memset(mul,0,sizeof(mul));
        for(int i=1;i<=q;i++){
            scanf("%d",&x);
            if(arr[x]==1){
                if(!vis[x]){
                    vis[x]=true;
                    ans+=tot;
                    tot++;
                    mul[1]++;
                }
                else {
                    vis[x]=false;
                    ans-=tot-1;
                    tot--;
                    mul[1]--;
                }
                cout<<ans<<endl;
                continue;
            }
        //  cout<<cf[arr[x]]<<endl;
            if(!vis[x]){
                vis[x]=true;
                gao(arr[x]);
        //      cout<<curans<<endl;
                ans+=curans;
                tot++;
                for(int i=0;i<c;i++)
                mul[cnum[i]]++;
            }
            else{
                vis[x]=false;
                gao(arr[x]);
                tot--;
                ans-=curans;
                for(int i=0;i<c;i++)
                mul[cnum[i]]--;
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int N=500010;

int fac[N][10],cf[N],mul[N];
int arr[N],cnum[500],c;
bool vis[N];
int tot=0,ans=0,curans;

void initial(){
    memset(cf,0,sizeof(cf));
    for(int i=2;i<N;i++){
        if(cf[i]) continue;
        for(int j=i;j<N;j+=i){
            fac[j][++cf[j]]=i;
        }
    }
}

void dfs(int num,int pos,int cnt,int val){
    if(pos>cf[num]){
        cnum[c++]=val;
        if(cnt&1) curans-=mul[val];
        else curans+=mul[val];
        return ;
    }
    dfs(num,pos+1,cnt,val);
    dfs(num,pos+1,cnt+1,val*fac[num][pos]);
}

void gao(int num){
    c=0;
    curans=0;
    dfs(num,1,0,1);
}

int main(){
    initial();
    int n,q,x;
    while(scanf("%d%d",&n,&q)!=EOF){
        for(int i=1;i<=n;i++){
            scanf("%d",&arr[i]);
            vis[i]=false;
        }
        memset(mul,0,sizeof(mul));
        for(int i=1;i<=q;i++){
            scanf("%d",&x);
            if(arr[x]==1){
                if(!vis[x]){
                    vis[x]=true;
                    ans+=tot;
                    tot++;
                    mul[1]++;
                }
                else {
                    vis[x]=false;
                    ans-=tot-1;
                    tot--;
                    mul[1]--;
                }
                printf("%d\n",ans);
                continue;
            }
        //  cout<<cf[arr[x]]<<endl;
            if(!vis[x]){
                vis[x]=true;
                gao(arr[x]);
        //      cout<<curans<<endl;
                ans+=curans;
                tot++;
                for(int i=0;i<c;i++)
                mul[cnum[i]]++;
            }
            else{
                vis[x]=false;
                gao(arr[x]);
                tot--;
                ans-=curans;
                for(int i=0;i<c;i++)
                mul[cnum[i]]--;
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#define LL long long
#define MAXN 500001
#define NN 200005
using namespace std;
int n, q;
int mob[MAXN], cnt[MAXN];
int noprime[MAXN], p[MAXN];
int star[MAXN], inSet[MAXN];
vector <int> mobNum[MAXN];

void Mobius()
{
    memset(noprime, 0, sizeof(noprime));
    int pnum = 0;
    mob[1] = 1;
    for(int i = 2; i < MAXN; i++)
    {
        if(!noprime[i])
        {
            p[pnum ++] = i;
            mob[i] = -1;
        }
        for(int j = 0; j < pnum && i * p[j] < MAXN; j++)
        {
            noprime[i * p[j]] = true;
            if(i % p[j] == 0)
            {
                mob[i * p[j]] = 0;
                break;
            }
            mob[i * p[j]] = -mob[i];
        }
    }
}

void init()
{
    for(int i = 0; i < MAXN; i++) mobNum[i].clear();
    for(int i = 1; i < MAXN; i++)
    {
        if(mob[i])
        {
            for(int j = i; j < MAXN; j += i)
            {
                mobNum[j].push_back(i);
            }
        }
    }
}

int main()
{
    //freopen("in.in", "r", stdin);
    Mobius();
    init();
    while(scanf("%d%d", &n, &q) != EOF)
    {
        memset(cnt, 0, sizeof(cnt));
        memset(inSet, 0, sizeof(inSet));
        for(int i = 1; i <= n; i++) scanf("%d", &star[i]);
        LL ans = 0;
        while(q--)
        {
            int x;
            scanf("%d", &x);
            int siz = mobNum[star[x]].size();
            LL temp;
            if(inSet[x])
            {
                temp = 0;
                for(int i = 0; i < siz; i++)
                {
                    int v = mobNum[star[x]][i];
                    cnt[v]--;
                    temp += ((LL)mob[v] * (LL)cnt[v]);
                }
                ans -= temp;
                inSet[x] = 0;
            }
            else
            {
                temp = 0;
                for(int i = 0; i < siz; i++)
                {
                    int v = mobNum[star[x]][i];
                    temp += ((LL)mob[v] * (LL)cnt[v]);
                    cnt[v]++;
                }
                ans += temp;
                inSet[x] = 1;
            }
            //cout << "--------------------" << star[x] << " " <<temp << endl;
            printf("%I64d\n", ans);
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define cout2(x, y) cout << x << " " << y << endl
#define N 200005
#define ones(x) __builtin_popcount(x)
using namespace std;

int fact[N];
void criba(){

    for(int i = 2; i * i < N; i++)
        if(fact[i] == 0)for(int j = i * i; j < N; j += i)fact[j] = i;

    for(int i = 2; i < N; i++)if(fact[i] == 0)fact[i] = i;
}

bool vis[N];
int F[N], a[N];

int mask[1<<9], primes[9];
vector<pair<int, int> >G[N];

int main(){

    int n, q;
    criba();

    while(cin>>n>>q){

        for(int i = 0; i < n; i++){

            scanf("%d", &a[i]);
            int num = a[i], top = 0;

            while(num > 1){

                int f = fact[num];
                while(num%f == 0)num /= f;
                primes[top++] = f;
            }

            mask[0] = 1;
            for(int j = 1, l; j < (1<<top); j++){

                l = 31 - __builtin_clz(j&-j);
                mask[j] = mask[j^(1<<l)] * primes[l];

                if(ones(j)%2 == 0)G[i].pb(make_pair(mask[j], 0));
                else G[i].pb(make_pair(mask[j], 1));
            }
        }

        long long pos, cur = 0, last = 0;
        long long ans, val, id;

        for(int i = 0; i < q; i++){

            scanf("%d", &pos);
            pos--;

            ans = cur;
            if(vis[pos]){

                for(int j = 0; j < G[pos].size(); j++){

                    val = G[pos][j].first;
                    id = G[pos][j].second;

                    if(id)ans -= F[val];
                    else ans += F[val];
                    F[val]--;
                }
                cur--;
            }
            else{

                for(int j = 0; j < G[pos].size(); j++){

                    val = G[pos][j].first;
                    id = G[pos][j].second;

                    if(id)ans -= F[val];
                    else ans += F[val];
                    F[val]++;
                }

                cur++;
            }

            if(vis[pos] && a[pos] == 1)ans--;
            //printf("%d %d %d\n", F[1], F[2], F[3]);
            if(vis[pos])ans = last - ans;
            else ans = last + ans;

            vis[pos] = 1 - vis[pos];
            printf("%I64d\n", ans);

            last = ans;
        }

    }

}


#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define cout2(x, y) cout << x << " " << y << endl
#define N 500005
#define ones(x) __builtin_popcount(x)
using namespace std;

int fact[N];
void criba(){

    for(int i = 2; i * i < N; i++)
        if(fact[i] == 0)for(int j = i * i; j < N; j += i)fact[j] = i;

    for(int i = 2; i < N; i++)if(fact[i] == 0)fact[i] = i;
}

bool vis[N];
int F[N], a[N];

int mask[1<<9], primes[9];
vector<pair<int, int> >G[N];

int main(){

    int n, q;
    criba();

    while(cin>>n>>q){

        for(int i = 0; i < n; i++){

            scanf("%d", &a[i]);
            int num = a[i], top = 0;

            while(num > 1){

                int f = fact[num];
                while(num%f == 0)num /= f;
                primes[top++] = f;
            }

            mask[0] = 1;

            for(int j = 1, l; j < (1<<top); j++){

                l = 31 - __builtin_clz(j&-j);
                mask[j] = mask[j^(1<<l)] * primes[l];

                if(ones(j)%2 == 0)G[i].pb(make_pair(mask[j], 0));
                else G[i].pb(make_pair(mask[j], 1));
            }

        }

        long long pos, cur = 0, last = 0;
        long long ans, val, id;

        for(int i = 0; i < q; i++){

            scanf("%d", &pos);
            pos--;

            ans = cur;
            if(vis[pos]){

                for(int j = 0; j < G[pos].size(); j++){

                    val = G[pos][j].first;
                    id = G[pos][j].second;

                    if(id)ans -= F[val];
                    else ans += F[val];
                    F[val]--;
                }
                cur--;
            }
            else{

                for(int j = 0; j < G[pos].size(); j++){

                    val = G[pos][j].first;
                    id = G[pos][j].second;

                    if(id)ans -= F[val];
                    else ans += F[val];
                    F[val]++;
                }

                cur++;
            }

            if(vis[pos] && a[pos] == 1)ans--;
            //printf("%d %d %d\n", F[1], F[2], F[3]);
            if(vis[pos])ans = last - ans;
            else ans = last + ans;

            vis[pos] = 1 - vis[pos];
            printf("%I64d\n", ans);

            last = ans;
        }

    }

}


#include<bits/stdc++.h>
#define maxn 5*100010

using namespace std;

vector<int>G[maxn];
int cnt[maxn], a[maxn];
bool in[maxn];

int query(int x)
{
    int ans = 0;
    int s = G[x].size();
    for(int i=0; i < (1<<s); i++)
    {
        int v = 1;
        int sign = 1;
        for(int k = 0; k < s; k++)
        {
            if(i>>k & 1)
                v*=G[x][k], sign*=-1;
        }
        ans+=sign*cnt[v];
    }
    return ans;
}
void add(int x,int w)
{
    int s = G[x].size();
    for(int i = 0; i < (1<<s); i++)
    {
        int v = 1;
        for(int k = 0; k < s; k++)
        {
            if(i>>k & 1)
                v*=G[x][k];
        }
        cnt[v]+=w;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    for(int j = 2; j < maxn; j++)
        if(G[j].empty())
            for(int i = j; i < maxn; i += j)
                G[i].push_back(j);
    int n,q;
    cin >> n >> q;
    for(int i = 0; i < n; i++) cin >> a[i];
    long long ans = 0;
    while(q--)
    {
        int i;
        cin >> i;
        i--;
        if(in[i])
        {
            add(a[i], -1);
            ans -= query(a[i]);
            in[i] = 0;
        }
        else
        {
            ans += query( a[i] );
            add( a[i] ,1);
            in[ i ] = 1;
        }
        cout << ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define maxn 5*100010

using namespace std;

vector<int>G[maxn];
int cnt[maxn], a[maxn];
bool in[maxn];

int query(int x)
{
    int ans = 0;
    int s = G[x].size();
    for(int i=0; i < (1<<s); i++)
    {
        int v = 1;
        int sign = 1;
        for(int k = 0; k < s; k++)
        {
            if(i>>k & 1)
                v*=G[x][k], sign*=-1;
        }
        ans+=sign*cnt[v];
    }
    return ans;
}
void add(int x,int w)
{
    int s = G[x].size();
    for(int i = 0; i < (1<<s); i++)
    {
        int v = 1;
        for(int k = 0; k < s; k++)
        {
            if(i>>k & 1)
                v*=G[x][k];
        }
        cnt[v]+=w;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    for(int j = 2; j < maxn; j++)
        if(G[j].empty())
            for(int i = j; i < maxn; i += j)
                G[i].push_back(j);
    int n,q;
    cin >> n >> q;
    for(int i = 0; i < n; i++) cin >> a[i];
    long long ans = 0;
    while(q--)
    {
        int i;
        cin >> i;
        i--;
        if(in[i])
        {
            add(a[i], -1);
            ans -= query(a[i]);
            in[i] = 0;
        }
        else
        {
            ans += query( a[i] );
            add( a[i] ,1);
            in[ i ] = 1;
        }
        cout << ans;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(a, b, c) for(int a = b; a < c; a++)
#define asd(x)              cout<<__LINE__<<" :: "<<#x<< ": "<<x<<endl;
#define asdf(x, y)          cout<<__LINE__<<" :: "<<#x<< ": "<<x<<" | "<<#y<< ": "<<y<<endl;
typedef pair<int,int> ii;
typedef long long LL;

const int maxx = 5e5 + 5;

vector<int> factors[maxx];
int a[maxx], store[maxx], cnt[maxx];
LL ans = 0;

void update(int val, int sign){

    int len = factors[val].size();

    REP(mask, 0, (1 << len)){

        int net = 1, CNT = 0;
        for(int bit = 0; bit < len; bit++) if( mask & (1 << bit) ) net = net * factors[val][bit], CNT++;

        if(sign == -1) cnt[net]--;

        int here = cnt[net];

        if(CNT & 1) ans -= here * sign;
        else ans += here * sign;

        if(sign == 1) cnt[net]++;
    }

}

int main(){

    REP(i, 2, maxx){
        if(factors[i].empty()){
            for(int j = i; j < maxx; j+= i) factors[j].push_back(i);
        }
    }

    int n, q;
    cin >> n >> q;
    REP(i, 0, n) scanf("%d", a + i);

    REP(i, 0, q) {
        int idx;
        scanf("%d", &idx);
        idx--;
    //    asdf(idx, a[idx]);
        update(a[idx], store[idx] ? -1 : 1);
        store[idx] ^= 1;
        printf("%lld\n", ans);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
int p[N][20];
int a[N], num[N], vis[N];
void Init() {
    for(int i = 0; i < N; ++i) p[i][0] = 0;
    p[1][0] = 1; p[1][1] = 1;
    for(int i = 2; i < N; ++i) if(!p[i][0]) {
        for(int j = i; j < N; j += i)
        p[j][ ++p[j][0] ] = i;
    }
}
void update(int x, int f) {
    int cnt = p[x][0];
    for(int i = 1; i < (1 << cnt); ++i) {
        int v = 1;
        for(int j = 1; j <= cnt; ++j) if(i & (1 << (j - 1))){
            v *= p[x][j];
        }
        if(f)
        num[v]--;
        else
        num[v]++;
    }
}
int query(int x) {
    int cnt = p[x][0], res = 0;
    for(int i = 1; i < (1 << cnt); ++i) {
        int g = 0, v = 1;
        for(int j = 1; j <= cnt; ++j) if(i & (1 << (j - 1))) {
            v *= p[x][j]; ++g;
        }
        if(g & 1) res += num[v];
        else res -= num[v];
    }
    return res;
}
int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    for(int i = 1; i <= n; ++i) scanf("%d", a + i);
    memset(num, 0, sizeof num);
    memset(vis, 0, sizeof vis);
    Init();
    int ans = 0, tot = 0;
    while(q --) {
        int x; scanf("%d", &x);
        if(vis[x]) {
            if(a[x] == 1)
            ans -= num[1] - 1;
           // else
            ans -= (tot - query(a[x]));
            update(a[x], 1);
            vis[x] = 0;
            tot--;
        }else {
            if(a[x] == 1)
            ans += num[1];
           // else
            ans += (tot - query(a[x]));
            vis[x] = 1;
            update(a[x], 0);
            tot++;
        }
        printf("%d\n", ans);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
int p[N][20];
int a[N], num[N];
void Init() {
    for(int i = 0; i < N; ++i) p[i][0] = 0;
    p[1][0] = 1; p[1][1] = 1;
    for(int i = 2; i < N; ++i) if(!p[i][0]) {
        for(int j = i; j < N; j += i)
        p[j][ ++p[j][0] ] = i;
    }
}
set<int> s;
void update(int x, int f) {
    int cnt = p[x][0];
    for(int i = 1; i < (1 << cnt); ++i) {
        int v = 1;
        for(int j = 1; j <= cnt; ++j) if(i & (1 << (j - 1))){
            v *= p[x][j];
        }
        if(f)
        num[v]--;
        else
        num[v]++;
    }
}
int query(int x) {
    int cnt = p[x][0], res = 0;
    for(int i = 1; i < (1 << cnt); ++i) {
        int g = 0, v = 1;
        for(int j = 1; j <= cnt; ++j) if(i & (1 << (j - 1))) {
            v *= p[x][j]; ++g;
        }
        if(g & 1) res += num[v];
        else res -= num[v];
    }
    return res;
}
int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    for(int i = 1; i <= n; ++i) scanf("%d", a + i);
    memset(num, 0, sizeof num);
    s.clear();
    Init();
    int ans = 0;
    while(q --) {
        int x; scanf("%d", &x);
        if(s.count(a[x])) {
            ans -= (s.size() - query(a[x]));
            update(a[x], 1);
            s.erase(a[x]);
        }else {
            ans += (s.size() - query(a[x]));
            s.insert(a[x]);
            update(a[x], 0);
        }
        printf("%d\n", ans);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int p[N][20];
int a[N], num[N];
void Init() {
    for(int i = 0; i < N; ++i) p[i][0] = 0;
    p[1][0] = 1; p[1][1] = 1;
    for(int i = 2; i < N; ++i) if(!p[i][0]) {
        for(int j = i; j < N; j += i)
        p[j][ ++p[j][0] ] = i;
    }
}
set<int> s;
void update(int x, int f) {
    int cnt = p[x][0];
    for(int i = 1; i < (1 << cnt); ++i) {
        int v = 1;
        for(int j = 1; j <= cnt; ++j) if(i & (1 << (j - 1))){
            v *= p[x][j];
        }
        if(f)
        num[v]--;
        else
        num[v]++;
    }
}
int query(int x) {
    int cnt = p[x][0], res = 0;
    for(int i = 1; i < (1 << cnt); ++i) {
        int g = 0, v = 1;
        for(int j = 1; j <= cnt; ++j) if(i & (1 << (j - 1))) {
            v *= p[x][j]; ++g;
        }
        if(g & 1) res += num[v];
        else res -= num[v];
    }
    return res;
}
int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    for(int i = 1; i <= n; ++i) scanf("%d", a + i);
    memset(num, 0, sizeof num);
    s.clear();
    Init();
    int ans = 0;
    while(q --) {
        int x; scanf("%d", &x);
        if(s.count(a[x])) {
            ans -= (s.size() - query(a[x]));
            update(a[x], 1);
            s.erase(a[x]);
        }else {
            ans += (s.size() - query(a[x]));
            s.insert(a[x]);
            update(a[x], 0);
        }
        printf("%d\n", ans);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
int p[N][20];
int a[N], num[N], vis[N];
void Init() {
    for(int i = 0; i < N; ++i) p[i][0] = 0;
    p[1][0] = 1; p[1][1] = 1;
    for(int i = 2; i < N; ++i) if(!p[i][0]) {
        for(int j = i; j < N; j += i)
        p[j][ ++p[j][0] ] = i;
    }
}
void update(int x, int f) {
    int cnt = p[x][0];
    for(int i = 1; i < (1 << cnt); ++i) {
        int v = 1;
        for(int j = 1; j <= cnt; ++j) if(i & (1 << (j - 1))){
            v *= p[x][j];
        }
        if(f)
        num[v]--;
        else
        num[v]++;
    }
}
int query(int x) {
    int cnt = p[x][0], res = 0;
    for(int i = 1; i < (1 << cnt); ++i) {
        int g = 0, v = 1;
        for(int j = 1; j <= cnt; ++j) if(i & (1 << (j - 1))) {
            v *= p[x][j]; ++g;
        }
        if(g & 1) res += num[v];
        else res -= num[v];
    }
    return res;
}
int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    for(int i = 1; i <= n; ++i) scanf("%d", a + i);
    memset(num, 0, sizeof num);
    memset(vis, 0, sizeof vis);
    Init();
    int ans = 0, tot = 0;
    while(q --) {
        int x; scanf("%d", &x);
        if(vis[x]) {
            ans -= (tot - query(a[x]));
            update(a[x], 1);
            vis[x] = 0;
            tot--;
        }else {
            ans += (tot - query(a[x]));
            vis[x] = 1;
            update(a[x], 0);
            tot++;
        }
        printf("%d\n", ans);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int p[N][15];
int a[N], num[N];
void Init() {
    for(int i = 0; i < N; ++i) p[i][0] = 0;
    p[1][0] = 1; p[1][1] = 1;
    for(int i = 2; i < N; ++i) if(!p[i][0]) {
        for(int j = i; j < N; j += i)
        p[j][ ++p[j][0] ] = i;
    }
}
set<int> s;
void update(int x, int f) {
    int cnt = p[x][0];
    for(int i = 1; i < (1 << cnt); ++i) {
        int v = 1;
        for(int j = 1; j <= cnt; ++j) if(i & (1 << (j - 1))){
            v *= p[x][j];
        }
        if(f)
        num[v]--;
        else
        num[v]++;
    }
}
int query(int x) {
    int cnt = p[x][0], res = 0;
    for(int i = 1; i < (1 << cnt); ++i) {
        int g = 0, v = 1;
        for(int j = 1; j <= cnt; ++j) if(i & (1 << (j - 1))) {
            v *= p[x][j]; ++g;
        }
        if(g & 1) res += num[v];
        else res -= num[v];
    }
    return res;
}
int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    for(int i = 1; i <= n; ++i) scanf("%d", a + i);
    memset(num, 0, sizeof num);
    s.clear();
    Init();
    int ans = 0;
    while(q --) {
        int x; scanf("%d", &x);
        if(s.count(a[x])) {
            ans -= (s.size() - query(a[x]));
            update(a[x], 1);
            s.erase(a[x]);
        }else {
            ans += (s.size() - query(a[x]));
            s.insert(a[x]);
            update(a[x], 0);
        }
        printf("%d\n", ans);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5 + 10;
int p[N][25];
int a[N], num[N], vis[N];
void Init() {
    for(int i = 0; i < N; ++i) p[i][0] = 0;
    p[1][0] = 1; p[1][1] = 1;
    for(int i = 2; i < N; ++i) if(!p[i][0]) {
        for(int j = i; j < N; j += i)
        p[j][ ++p[j][0] ] = i;
    }
}
void update(int x, int f) {
    int cnt = p[x][0];
    for(int i = 1; i < (1 << cnt); ++i) {
        int v = 1;
        for(int j = 1; j <= cnt; ++j) if(i & (1 << (j - 1))){
            v *= p[x][j];
        }
        if(f)
        num[v]--;
        else
        num[v]++;
    }
}
ll query(int x) {
    int cnt = p[x][0], res = 0;
    for(int i = 1; i < (1 << cnt); ++i) {
        int g = 0, v = 1;
        for(int j = 1; j <= cnt; ++j) if(i & (1 << (j - 1))) {
            v *= p[x][j]; ++g;
        }
        if(g & 1) res += num[v];
        else res -= num[v];
    }
    return res;
}
int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    for(int i = 1; i <= n; ++i) scanf("%d", a + i);
    memset(num, 0, sizeof num);
    memset(vis, 0, sizeof vis);
    Init();
    ll ans = 0, tot = 0;
    while(q --) {
        int x; scanf("%d", &x);
        if(vis[x]) {
            if(a[x] == 1)
            ans -= num[1] - 1;
           // else
            ans -= (tot - query(a[x]));
            update(a[x], 1);
            vis[x] = 0;
            tot--;
        }else {
            if(a[x] == 1)
            ans += num[1];
           // else
            ans += (tot - query(a[x]));
            vis[x] = 1;
            update(a[x], 0);
            tot++;
        }
        printf("%I64d\n", ans);
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<map>
#include<set>
#include<vector>
#include<utility>
#include<queue>
#include<stack>

#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define LET(x, a)  __typeof(a) x(a)
#define foreach(it, v) for(LET(it, v.begin()); it != v.end(); it++)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

#define tr(x) cout<<x<<endl;
#define tr2(x,y) cout<<x<<" "<<y<<endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(w,x,y,z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<endl;

using namespace std;

int n, q, a[200100], cnt[500500], lp[500500], in[200100], val[64], bitcount[64], lsb[64], x;
long long ans;

void update(int x, int sign){
	int pcnt = 0, tmp = x;
	vector<int> primes;
	while(tmp > 1){
		int p = lp[tmp]; pcnt++;
		primes.pb(p);
		while(tmp%p == 0) tmp /= p;
	}

	for(int mask = 0; mask < (1<<pcnt); mask++){
		if(mask > 0)
			val[mask] = primes[lsb[mask]] * val[mask ^ (1<<lsb[mask])];
		else
			val[mask] = 1;

		if(sign < 0) cnt[val[mask]]--;

		if(bitcount[mask]%2 == 0) ans += sign*cnt[val[mask]]; else ans -= sign*cnt[val[mask]];

		if(sign > 0) cnt[val[mask]]++;
	}

}

int main(){
	sd2(n,q);
	for(int i = 0; i < n; i++){
		sd(a[i]);
	}

	memset(lp, -1, sizeof lp);
	for(int i = 2; i <= 500000; i++){
		if(lp[i] == -1)
			for(int j = i; j <= 500000; j += i) lp[j] = i;
	}

	for(int i = 0; i < 64; i++){
		for(int j = 0; j < 6; j++){
			if((i&(1<<j)) > 0) bitcount[i]++, lsb[i] = j;
		}
	}

	while(q--){
		sd(x);
		in[x] ^= 1;
		if(in[x]) update(a[x-1],1); else update(a[x-1],-1);
		printf("%I64d\n", ans);
	}

	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = (1<<21)+10;
typedef long long ll;
const int maxn = 20;

ll dp[N];
int c[110][110];
char s[110][110];
int lowzero(int s){
    int i;
    for(i=0;i<=20;i++){
        if( (1<<i)>s ) break;
        if( ((1<<i)&s) == 0) return i;
    }
    return i;
}

int main(){
    int n,m;
    cin >> n >> m;
    for(int i=0;i<n;i++) scanf("%s",s[i]);
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            scanf("%d",&c[i][j]);
    int size = (1<<n)-1;
    for(int i=size;i>0;i--) dp[i] = 1e8;
    dp[0] = 0;
    for(int j=0;j<=size;j++){
        int k = lowzero(j);
        for(int i=0;i<m;i++){
            dp[j|(1<<k)] = min(dp[j|(1<<k)] , dp[j]+c[k][i]);
            int hehe = 0 , mx = 0 ,co = 0;
            for(int p=0;p<n;p++)
            if(s[p][i]==s[k][i])
            {
                hehe |= (1<<p);
                mx = max(mx,c[p][i]);
                co += c[p][i];
            }
            co -= mx;
            dp[j|hehe] = min(dp[j|hehe] , dp[j]+co);
        }
    }
    ll ans = dp[size];
    printf("%I64d\n",ans);
    return 0;
}

/*
in 0 lowzero is 0
in 1 lowzero is 1
in 2 lowzero is 0
in 3 lowzero is 2
in 4 lowzero is 0
in 5 lowzero is 1
in 6 lowzero is 0
in 7 lowzero is 3
in 8 lowzero is 0
in 9 lowzero is 1
in 10 lowzero is 0
in 11 lowzero is 2
in 12 lowzero is 0
in 13 lowzero is 1
in 14 lowzero is 0
in 15 lowzero is 4
*/


#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 5*100000+10;
const int maxn = 5*100000;

int cnt[N],pri[N],vis[N],num;
vector<int> gc[N];

void init(){
    memset(cnt,0,sizeof(cnt));
    memset(vis,0,sizeof(vis));
    for(int i=0;i<=maxn;i++)
        gc[i].clear();
//    num=0;
//    for(long long i=2;i<=maxn;i++)
//    for(long long j=i*i;j<=maxn;j+=i)
//        vis[j] = 1;
//
//    for(int i=2;i<=maxn;i++)
//    if(!vis[i])
//        pri[++num] = i;

    for(int i=2;i<=maxn;i++) if(!gc[i].size())
        for(int j=i;j<=maxn;j+=i)
            gc[j].push_back(i);
}

void add(int x,int y){
    int size = gc[x].size();
    for(int i=0;i<(1<<size);i++){
        int tmp=1;
        for(int j=0;j<size;j++)
        if(i&(1<<j)){
            tmp *= gc[x][j];
        }
        cnt[tmp] += y;
    }
}

int cal(int x){
    int ans = 0;
    int size = gc[x].size();
    for(int i=0;i<(1<<size);i++){
        int tmp = 1, fl = 1;
        for(int j=0;j<size;j++)
        if(i&(1<<j)){
            tmp *= gc[x][j];
            fl *= -1;
        }
        ans += fl*cnt[tmp];
    }
//    printf("hehe  %d\n",ans);
    return ans;
}

int a[N],fl[N];
int main(){
    int n,q,x;
    cin >> n >> q;
    init();
    memset(fl,0,sizeof(fl));
    int ans = 0;
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=q;i++){
        scanf("%d",&x);
        x = a[x];
        if(!fl[x]){
            ans += cal(x);
            add(x,1);
            fl[x] = 1;
        }
        else{
            add(x,-1);
            ans -= cal(x);
            fl[x] = 0;
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 5*100000+10;
const int maxn = 5*100000;

int cnt[N],pri[N],vis[N],num;
vector<int> gc[N];

void init(){
    memset(cnt,0,sizeof(cnt));
    for(int i=0;i<=maxn;i++)
        gc[i].clear();

    for(int i=2;i<=maxn;i++) if(gc[i].size()==0)
        for(int j=i;j<=maxn;j+=i)
            gc[j].push_back(i);
}

void add(int x,int y){
    int size = gc[x].size();
    for(int i=0;i<(1<<size);i++){
        int tmp=1;
        for(int j=0;j<size;j++)
        if(i&(1<<j)){
            tmp *= gc[x][j];
        }
        cnt[tmp] += y;
    }
}

int cal(int x){
    int ans = 0;
    int size = gc[x].size();
    for(int i=0;i<(1<<size);i++){
        int tmp = 1, fl = 1;
        for(int j=0;j<size;j++)
        if(i&(1<<j)){
            tmp *= gc[x][j];
            fl *= -1;
        }
        ans += fl*cnt[tmp];
    }
//    printf("hehe  %d\n",ans);
    return ans;
}

int a[N],fl[N];
int main(){
    int n,q,x;
    cin >> n >> q;
    init();
    memset(fl,0,sizeof(fl));
    long long ans = 0;
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=q;i++){
        scanf("%d",&x);
        if(!fl[x]){
            ans += cal(a[x]);
            add(a[x],1);
            fl[x] = 1;
        }
        else{
            add(a[x],-1);
            ans -= cal(a[x]);
            fl[x] = 0;
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 5*100000+10;
const int maxn = 5*100000;

int cnt[N],pri[N],vis[N],num;
vector<int> gc[N];

void init(){
    memset(cnt,0,sizeof(cnt));
    for(int i=0;i<=maxn;i++)
        gc[i].clear();

    for(int i=2;i<=maxn;i++) if(gc[i].size()==0)
        for(int j=i;j<=maxn;j+=i)
            gc[j].push_back(i);
}

void add(int x,int y){
    int size = gc[x].size();
    for(int i=0;i<(1<<size);i++){
        int tmp=1;
        for(int j=0;j<size;j++)
        if(i&(1<<j)){
            tmp *= gc[x][j];
        }
        cnt[tmp] += y;
    }
}

int cal(int x){
    int ans = 0;
    int size = gc[x].size();
    for(int i=0;i<(1<<size);i++){
        int tmp = 1, fl = 1;
        for(int j=0;j<size;j++)
        if(i&(1<<j)){
            tmp *= gc[x][j];
            fl *= -1;
        }
        ans += fl*cnt[tmp];
    }
//    printf("hehe  %d\n",ans);
    return ans;
}

int a[N],fl[N];
int main(){
    int n,q,x;
    cin >> n >> q;
    init();
    memset(fl,0,sizeof(fl));
    long long ans = 0;
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=q;i++){
        scanf("%d",&x);
        if(!fl[x]){
            ans += cal(a[x]);
            add(a[x],1);
            fl[x] = 1;
        }
        else{
            add(a[x],-1);
            ans -= cal(a[x]);
            fl[x] = 0;
        }
        printf("%I64d\n",ans);
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 5*100000+10;
const int maxn = 5*100000;

int cnt[N],pri[N],vis[N],num;
vector<int> gc[N];

void init(){
    memset(cnt,0,sizeof(cnt));
    for(int i=0;i<=maxn;i++)
        gc[i].clear();

    for(int i=2;i<=maxn;i++) if(gc[i].size()==0)
        for(int j=i;j<=maxn;j+=i)
            gc[j].push_back(i);
}

void add(int x,int y){
    int size = gc[x].size();
    for(int i=0;i<(1<<size);i++){
        int tmp=1;
        for(int j=0;j<size;j++)
        if(i&(1<<j)){
            tmp *= gc[x][j];
        }
        cnt[tmp] += y;
    }
}

int cal(int x){
    int ans = 0;
    int size = gc[x].size();
    for(int i=0;i<(1<<size);i++){
        int tmp = 1, fl = 1;
        for(int j=0;j<size;j++)
        if(i&(1<<j)){
            tmp *= gc[x][j];
            fl *= -1;
        }
        ans += fl*cnt[tmp];
    }
//    printf("hehe  %d\n",ans);
    return ans;
}

int a[N],fl[N];
int main(){
    int n,q,x;
    cin >> n >> q;
    init();
    memset(fl,0,sizeof(fl));
    int ans = 0;
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=q;i++){
        scanf("%d",&x);
        if(!fl[x]){
            x = a[x];
            ans += cal(x);
            add(x,1);
            fl[x] = 1;
        }
        else{
            x = a[x];
            add(x,-1);
            ans -= cal(x);
            fl[x] = 0;
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 5*100000+10;
const int maxn = 5*100000;

int cnt[N],pri[N],vis[N],num;
vector<int> gc[N];

void init(){
    memset(cnt,0,sizeof(cnt));
    for(int i=0;i<=maxn;i++)
        gc[i].clear();

    for(int i=2;i<=maxn;i++) if(gc[i].size()==0)
        for(int j=i;j<=maxn;j+=i)
            gc[j].push_back(i);
}

void add(int x,int y){
    int size = gc[x].size();
    for(int i=0;i<(1<<size);i++){
        int tmp=1;
        for(int j=0;j<size;j++)
        if(i&(1<<j)){
            tmp *= gc[x][j];
        }
        cnt[tmp] += y;
    }
}

int cal(int x){
    int ans = 0;
    int size = gc[x].size();
    for(int i=0;i<(1<<size);i++){
        int tmp = 1, fl = 1;
        for(int j=0;j<size;j++)
        if(i&(1<<j)){
            tmp *= gc[x][j];
            fl *= -1;
        }
        ans += fl*cnt[tmp];
    }
//    printf("hehe  %d\n",ans);
    return ans;
}

int a[N],fl[N];
int main(){
    int n,q,x;
    cin >> n >> q;
    init();
    memset(fl,0,sizeof(fl));
    int ans = 0;
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=q;i++){
        scanf("%d",&x);
        if(!fl[x]){
            ans += cal(a[x]);
            add(a[x],1);
            fl[x] = 1;
        }
        else{
            add(a[x],-1);
            ans -= cal(a[x]);
            fl[x] = 0;
        }
        printf("%d\n",ans);
    }
    return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <memory.h>
#include <set>
#include <ctime>
#include <map>
#include <cstring>
#include <iterator>
#include <queue>

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pdd pair<double, double>
#define pldld pair<ld, ld>
#define mp make_pair
#define ull unsigned long long
#define pss pair<string, string>
#pragma comment(linker, "/STACK:64000000")
#define null NULL

const int infi = 1e9 + 7;
const ll infl = 1e18;
const long double eps = (ld)1e-8;
const long double eps1 = 1e-10;
const int mod = (1e9 + 7);
const ll mod1 = (1e9 + 7);
const ll mod2 = 1e9 + 9;
const ll mod3 = (ll)(1e9);
const ll p1 = 31;
const ll p2 = 37;
const ll p3 = 29;
const ull maxn = 10000000000000000LL;
const ull maxres = 800000;

int resh[500500];
int s[500500];
int fc[20];
int fact(int a) {
    int sz = 0;
    while (a > 1 && resh[a]) {
        fc[sz] = resh[a];
        while (!(a % fc[sz])) {
            a /= fc[sz];
        }
        ++sz;
    }
    if (a > 1) {
        fc[sz++] = a;
    }
    return sz;
}
int flag;
int getans(int i, int a, int sum) {
    if (i < 0) {
        int ans;
        if (flag == 1) {
            if (sum & 1) {
                ans = -s[a];
            }
            else {
                ans = s[a];
            }
            s[a]++;
        }
        else {
            --s[a];
            if (sum & 1) {
                ans = -s[a];
            }
            else {
                ans = s[a];
            }
        }
        return ans;
    }
    return getans(i - 1, a, sum) + getans(i - 1, a * fc[i], sum + 1);
}
int ar[200500];
int used[200500];

int main() {
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    //freopen(".in", "r", stdin); freopen(".out", "w", stdout);
    for (int i = 2; i * i < 500500; ++i) {
        if (!resh[i]) {
            for (int j = i * i; j < 500500; j += i) {
                resh[j] = i;
            }
        }
    }
    int n, q;
    cin >> n >> q;
    ll ans =0;
    for (int i = 0; i < n; ++i) {
        cin >> ar[i];
    }
    for (;q;--q) {
        int x;
        cin >> x;
        if (used[x -1]) {
            flag = -1;
        }
        else {
            flag = 1;
        }
        used[x - 1] ^= 1;
        ans += (ll)getans(fact(ar[x - 1]) - 1, 1, 0) * (ll)flag;
        cout << ans << endl;
    }
    return 0;
}