# E. Mike and Foam (the principle of repulsion)

Source: Internet
Author: User

E. Mike and Foam

Mike is a bartender at Rico ' s bar. At Rico ' s, they put beer glasses in a special shelf. There isn kinds of beer at Rico ' s numbered from 1 to n. i-th kind of beer haveai milliliters of foam on it.

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 numberx. 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 all query, Mike should tell him the score of the shelf. Bears is geeks. So they think then the score of a shelfis the number of pairs (i,? J) of glasses in the shelf such thati? <? J and where is the greatest common divisor of numbersa and b.

Mike is tired. So he asked the him in performing these requests.

Input

The first line of input contains numbers n andq (1?≤? N,? q. ≤?2?x?105), the number of different kinds of beer and number of queries.

The next line contains n space separated integers,a1,? A2,?...,? An (1?≤? ) Ai-≤?5?x?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 integerx (1?≤? x? ≤? n), the index of a beer that should is added or removed from the shelf.

Output

For each query, print the answer.

Sample Test (s) Input
`5 61 2 3 4 6123451`
Output
`013562`

Test instructions easy to understand, I will not say ...

Problem: The topic can be converted to, in a dynamic set, did not add a number, or take out a number, the remaining number of coprime of how many pairs, attention is unordered. Because the number of qualitative factors in the data range of the topic is very small, the complexity can be negligible, so we can decompose the mass factor for each new number added or the number taken out. Then through the tolerant principle, first calculate how many of the set is not coprime, this is easy to calculate it! (If I can't think of a way to look at my code, it's just an array to count, quite simply). Know not coprime, nature will know coprime spicy! Then subtract or add the number of coprime to the answer. Time complexity estimates the 10^7 level.

E. Mike and Foam (the principle of repulsion)

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.