CF1878F.Vasilije Loves Number Theory

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vasilije is a smart student and his discrete mathematics teacher Sonja taught him number theory very well.

He gave Ognjen a positive integer nn.

Denote d(n)d(n) as the number of positive integer divisors of nn, and denote gcd(a,b)gcd(a, b) as the largest integer gg such that aa is divisible by gg and bb is divisible by gg.

After that, he gave Ognjen qq queries, and there are 22 types of queries.

  • 11, xx — set nn to n⋅xn \cdot x, and then answer the following question: does there exist a positive integer aa such that gcd(a,n)=1gcd(a, n) = 1, and d(n⋅a)=nd(n \cdot a) = n?
  • 22 — reset nn to its initial value (before any queries).

Note that nn does not get back to its initial value after the type 1 query.

Since Ognjen is afraid of number theory, Vasilije promised him that after each query, d(n)≤109d(n) \le 10^9, however, even with that constraint, he still needs your help with this problem.

瓦西利耶是一位聪明的学生,他的离散数学老师索尼亚将数论知识教得非常好。

他给了奥格年一个正整数 nn。

记 d(n)d(n) 为 nn 的正整数约数的个数,记 gcd(a,b)gcd(a, b) 为最大的整数 gg,使得 aa 和 bb 均能被 gg 整除。

接着,他给了奥格年 qq 个查询,查询分为两类:

  • 1 x1\ x —— 将 nn 更新为 n⋅xn \cdot x,然后回答如下问题:是否存在一个正整数 aa,满足 gcd(a,n)=1gcd(a, n) = 1,且 d(n⋅a)=nd(n \cdot a) = n?
  • 22 —— 将 nn 重置为其初始值(即所有查询执行前的原始值)。

注意:在类型 1 的查询中,nn 不会自动恢复为初始值。

由于奥格年害怕数论,瓦西利耶向他保证:每次查询之后均有 d(n)≤109d(n) \le 10^9。然而,即便有这一约束,他仍需要你的帮助来解决此问题。

输入格式

The first line contains a positive integer tt, (1≤t≤1001 \le t \le 100) — the number of test cases.

The first line of each test case contains 22 integers, nn and qq (1≤n≤1061 \le n \le 10^{6}, 1≤q≤10001\le q \le 1000) — the number nn and the number of queries.

The following qq lines contain an integer kk (1≤k≤21 \le k \le 2), if k=1k=1 then there is another integer in this line xx (1≤x≤1061 \le x \le 10^6) — the description of the queries.

It is guaranteed that, for the given input, d(n)d(n) does not exceed 10910^9 at any point.

It is guaranteed that the sum of qq over all test cases doesn't exceed 10310^3.

第一行包含一个正整数 tt(1≤t≤1001 \le t \le 100)——测试用例的数量。

每个测试用例的第一行包含两个整数 nn 和 qq(1≤n≤1061 \le n \le 10^{6},1≤q≤10001\le q \le 1000)——分别为数字 nn 和查询次数。

接下来的 qq 行每行包含一个整数 kk(1≤k≤21 \le k \le 2);若 k=1k=1,则该行还包含另一个整数 xx(1≤x≤1061 \le x \le 10^6)——用于描述查询。

保证对于给定的输入,在任意时刻 d(n)d(n) 均不超过 10910^9。

保证所有测试用例中 qq 的总和不超过 10310^3。

输出格式

For each type 1 query, you should output "YES" if there exist such positive integer aa that gcd(a,n)=1gcd(a, n) = 1 and d(n⋅a)=nd(n \cdot a)=n, and "NO" if he can't.

You can output the answer in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as a positive answer).

对于每个类型 1 的查询,若存在正整数 aa 满足 gcd⁡(a,n)=1\gcd(a, n) = 1 且 d(n⋅a)=nd(n \cdot a)=n,则输出 “YES”;否则输出 “NO”。

你可以以任意大小写形式输出答案(例如,字符串 “yEs”、“yes”、“Yes” 和 “YES” 均被视为肯定回答)。

输入输出样例

  • 输入#1

    7
    1 5
    1 1
    1 2
    2
    1 8
    1 9
    20 4
    1 3
    2
    1 7
    1 12
    16 10
    1 6
    1 6
    1 10
    1 9
    1 1
    1 9
    1 7
    1 3
    1 2
    1 10
    9 1
    1 3
    8 1
    1 2
    8 3
    1 5
    1 8
    1 10
    11 5
    1 8
    1 2
    1 1
    1 3
    1 1

    输出#1

    YES
    YES
    YES
    YES
    
    YES
    NO
    YES
    
    YES
    NO
    YES
    YES
    YES
    NO
    YES
    NO
    YES
    YES
    
    NO
    
    NO
    
    YES
    NO
    NO
    
    YES
    NO
    NO
    NO
    NO

说明/提示

In the first test case, we initially have n=1n=1.

After the first query: n=1n=1, d(n)=1d(n)=1, so by taking a=1a = 1, d(n⋅a)=nd(n \cdot a) = n, and the answer to this query is "YES".

After the second query: n=2n=2, d(n)=2d(n)=2, we can, again, take a=1a = 1, d(n⋅a)=nd(n \cdot a) = n, and the answer to this query is "YES".

After the third query n=1n=1, and this is a type 22 query so we don't answer it.

After the fourth query: n=8n=8, and by taking a=3a=3, d(n⋅a)=d(24)=8=nd(n \cdot a) = d(24) = 8 = n, so the answer is "YES".

After the fifth query: n=72n=72, now we can take a=637a=637 to get n⋅a=45864n \cdot a = 45864, and d(n⋅a)=72=nd(n \cdot a) = 72 = n, so the answer is "YES".

In the second test case, we initially have n=20n=20.

After the first query: n=60n=60, and the answer is "YES".

After the second query: n=20n=20, this is a type 22 query, so we don't answer it.

After the third query: n=140n=140, and it can be proven that no matter which positive integer aa we take, d(n⋅a)d(n \cdot a) will never be equal to nn, so the answer to this query is "NO".

After the fourth query: n=1680n=1680. It can be proven that there exists a positive integer aa, such that d(n⋅a)=nd(n \cdot a) = n, so the answer is "YES".

在第一个测试用例中,初始时 n=1n=1。

第一次查询后:n=1n=1,d(n)=1d(n)=1,此时取 a=1a = 1,有 d(n⋅a)=d(1)=1=nd(n \cdot a) = d(1) = 1 = n,因此该查询的答案为 “YES”。

第二次查询后:n=2n=2,d(n)=2d(n)=2,同样可取 a=1a = 1,满足 d(n⋅a)=d(2)=2=nd(n \cdot a) = d(2) = 2 = n,因此该查询的答案为 “YES”。

第三次查询:n=1n=1,这是一个类型 22 的查询,因此无需回答。

第四次查询:n=8n=8,此时取 a=3a=3,有 n⋅a=24n \cdot a = 24,且 d(n⋅a)=d(24)=8=nd(n \cdot a) = d(24) = 8 = n,因此答案为 “YES”。

第五次查询:n=72n=72,此时取 a=637a=637,可得 n⋅a=45864n \cdot a = 45864,且 d(n⋅a)=72=nd(n \cdot a) = 72 = n,因此答案为 “YES”。

在第二个测试用例中,初始时 n=20n=20。

第一次查询后:n=60n=60,答案为 “YES”。

第二次查询:n=20n=20,这是一个类型 22 的查询,因此无需回答。

第三次查询:n=140n=140,可以证明:无论取哪个正整数 aa,d(n⋅a)d(n \cdot a) 均不可能等于 nn,因此该查询的答案为 “NO”。

第四次查询:n=1680n=1680。可以证明:存在某个正整数 aa,使得 d(n⋅a)=nd(n \cdot a) = n,因此答案为 “YES”。

输入解题思路,AI测评打分。不知道怎么写?

首页