Sensei will be adding to or removing numbers (x
) from a set. 2 numbers in the set are a co-prime pair if and only if gcd(a, b) = 1
. As Sensei add or remove numbers from the set, the number of co-prime pairs in the set changes. You are to inform him the latest number of co-prime pairs as that happens.
gcd stands for "greatest common denominator", which is also known as HCF (highest common factor).
The first line consists of 1 integer N
.
The next N
lines each contains 2 numbers, each describing an operation in the form of 1 of the following:
1 x
: Sensei is insertingx
to the set2 x
: Sensei is removingx
from the set (it is guaranteed that x exists in the set)
Your output should consist of N
lines, each line containing the number of pairs of co-prime numbers in the set.
Input 1
7
1 1
1 2
1 3
1 5
2 3
1 8
2 8
Output 1
0
1
3
6
3
5
3
For all cases:
1 <= N <= 50000, 1 <= x <= 50000
# | Points | Constraints |
---|---|---|
1 | 20 | N <= 100 |
2 | 20 | x 's are all prime numbers |
3 | 30 | x 's are all powers of prime numbers |
4 | 30 | no additional constraint |