2795.Mike and Foam

Time Limit: 1s Memory Limit: 256MB

Mike is a bartender at Rico's bar. At Rico's, they put beer glasses in a special shelf. There are n kinds of beer at Rico's numbered from 1 to n. i-th kind of beer has ai milliliters of foam on it. 2795_1.png Maxim is Mike's boss. Today he told Mike to perform q queries. Initially the shelf is empty. In each request, Maxim gives him a number x. If beer number x is already in the shelf, then Mike should remove it from the shelf, otherwise he should put it in the shelf.After each query, Mike should tell him the score of the shelf. Bears are geeks. So they think that the score of a shelf is the number of pairs (i,j) of glasses in the shelf such that i \lt j and 2795_2.png where 2795_3.png is the greatest common divisor of numbers a and b.Mike is tired. So he asked you to help him in performing these requests.

Input Format(From the terminal/stdin)

Input The first line of input contains numbers n and q (1 \le n,q \le 2 \times 105), the number of different kinds of beer and number of queries.The next line contains n space separated integers, a1,a2,... ,an (1 \le ai \le 5 \times 105), the height of foam in top of each kind of beer.The next q lines contain the queries. Each query consists of a single integer integer x (1 \le x \le n), the index of a beer that should be added or removed from the shelf.

Output Format(To the terminal/stdout)

Output For each query, print the answer for that query in one line.

Sample Input

Copy
5 6
1 2 3 4 6
1
2
3
4
5
1
 · \n
 · · · · \n
 \n
 \n
 \n
 \n
 \n
 \n

Sample Output

Copy
0
1
3
5
6
2
 \n
 \n
 \n
 \n
 \n
 \n

Submit

请先 登录

© 2025 FAQs