QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#13239. Number Collection

Statistics

Little H is a collector who loves collecting positive integers. Little H has a habit: before going to sleep, he calculates how many pairs of positive integers among all the positive integers he has collected have a greatest common divisor (GCD) exactly equal to $k$.

Every day, Little H might collect a new positive integer, or he might discard a positive integer for some reason. This means the set of positive integers he has collected is constantly changing, and the value calculated before sleep might be different each day. However, $k$ never changes. At the same time, Little H guarantees that $k$ is either $1$ or a prime number.

Little H wants to know, after each time he collects a new positive integer or discards a positive integer, how many pairs of positive integers have a greatest common divisor equal to $k$.

Input

The first line contains two integers $n$ and $k$. The next $n$ lines each contain two integers $a$ and $b$.

  • If $a = 0$, it means Little H discards a positive integer $b$ that he has collected. If Little H does not currently have $b$ in his collection, it might be that Little H misremembered, so no changes need to be made.
  • If $a = 1$, it means Little H collects a new positive integer $b$. Note that Little H can collect many identical positive integers.

Output

Output $n$ lines, each containing one integer, representing the answer after each discard or collection operation.

Constraints

Let $z$ be the maximum value among all positive integers collected by Little H. For all data, $1 \le k \le z$.

Test Case ID $n$ $z$ Test Case ID $n$ $z$
1 $\le 70$ $\le 10^5$ 11 $\le 10^5$ $\le 10^5$
2 12
3 13
4 14
5 $\le 1000$ 15
6 16
7 17
8 18
9 19
10 20

Examples

Input 1

5 2
1 2
1 4
0 2
1 2
1 2

Output 1

0
1
0
1
3

Input 2

8 3
1 3
0 3
0 3
1 3
1 6
1 9
1 12
1 2

Output 2

0
0
0
0
1
3
5
5

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.