#P8954. 「VUSC」Math Game

「VUSC」Math Game

Background

upd 2023.1.22: Added one set of hack testdata by

https://www.luogu.com.cn/user/585805

Bessie, far away in Moo-lica, also wants to visit friends and relatives during the Spring Festival. To kill time, she often plays an interesting number game with Farmer John.

Problem Description

Farmer John has a set SS, initially 2,3,4,ldots,N\\{2,3,4,\\ldots,N\\}.

For two positive integers p,qp, q in the set SS, we call them "a pair of good numbers" if and only if pk=q(kge2landkinN)p^k = q \\ (k\\ge 2 \\land k\\in\\N).

We treat each number in SS as a node in an undirected graph. For each pair of "good numbers", we add an undirected edge between these two numbers.

Farmer John will perform QQ operations of the following two types:

  1. Given xx, ask for the size of the connected component containing node xx.
  2. Given xx, remove xx from SS. At the same time, node xx in the undirected graph is also removed.

Since Bessie is too slow, she wants you to help.

Input Format

The first line contains two positive integers N,QN, Q.

The next QQ lines each contain two positive integers opi,xiop_i, x_i. Here, opiop_i denotes the type of the operation.

It is guaranteed that xix_i is in the set SS.

Output Format

For each operation of type 11, output one positive integer per line, which is the answer to the query.

30 6
1 6
1 4
2 9
1 3
2 2
1 16
1
4
2
2

Hint

Sample Explanation

This is the original undirected graph (all nodes in the top row are isolated nodes):

This is the undirected graph after the first type 22 operation (node 99 is deleted):

This is the undirected graph after the second type 22 operation (node 22 is deleted):


Constraints

All testdata satisfy:

  • 2leNle10182\\le N \\le 10^{18}
  • 1leQle1061\\le Q \\le 10^6
  • xiinSx_i\\in S
  • opiin1,2op_i \\in \\{1,2\\}

Test points 1sim21\\sim 2 additionally satisfy 2leNle1052\\le N \\le 10^5, 1leQle1041\\le Q \\le 10^4.

Test points 3sim43\\sim 4 additionally satisfy that all xi=mpix_i = m^{p_i}, where mm is a constant satisfying mge2landminNm\\ge 2 \\land m\\in \\N.

Test points 5sim105\\sim 10 have no additional constraints.

Translated by ChatGPT 5