CF1792E.Divisors and Table

提高+/省选-

通过率:0%

时间限制:2.50s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an n×nn \times n multiplication table and a positive integer m=m1⋅m2m = m_1 \cdot m_2. A n×nn \times n multiplication table is a table with nn rows and nn columns numbered from 11 to nn, where ai,j=i⋅ja_{i, j} = i \cdot j.

For each divisor dd of mm, check: does dd occur in the table at least once, and if it does, what is the minimum row that contains dd.

给你一个 n×nn \times n 的乘法表和一个正整数 m=m1⋅m2m = m_1 \cdot m_2。一个 n×nn \times n 的乘法表是一个具有 nn 行和 nn 列的表格,行列编号均从 11 到 nn,其中第 ii 行第 jj 列的元素为 ai,j=i⋅ja_{i, j} = i \cdot j。

对 mm 的每个正因数 dd,请判断:dd 是否至少在该表中出现一次;若出现,求出包含 dd 的最小行号。

输入格式

The first line contains a single integer tt (1≤t≤101 \le t \le 10) — the number of test cases.

The first and only line of each test case contains three integers nn, m1m_1 and m2m_2 (1≤n≤1091 \le n \le 10^9; 1≤m1,m2≤1091 \le m_1, m_2 \le 10^9) — the size of the multiplication table and the integer mm represented as m1⋅m2m_1 \cdot m_2.

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

每个测试用例仅有一行,包含三个整数 nn、m1m_1 和 m2m_2(1≤n≤1091 \le n \le 10^9;1≤m1,m2≤1091 \le m_1, m_2 \le 10^9)—— 分别表示乘法表的大小,以及以 m=m1⋅m2m = m_1 \cdot m_2 形式给出的整数 mm。

输出格式

For each test case, let d1,d2,…,dkd_1, d_2, \dots, d_k be all divisors of mm sorted in the increasing order. And let a1,a2,…,aka_1, a_2, \dots, a_k be an array of answers, where aia_i is equal to the minimum row index where divisor did_i occurs, or 00, if there is no such row.

Since array aa may be large, first, print an integer ss — the number of divisors of mm that are present in the n×nn \times n table. Next, print a single value X=a1⊕a2⊕⋯⊕akX = a_1 \oplus a_2 \oplus \dots \oplus a_k, where ⊕\oplus denotes the bitwise XOR operation.

对于每个测试用例,设 d1,d2,…,dkd_1, d_2, \dots, d_k 为 mm 的所有正因数,并按升序排列。再设 a1,a2,…,aka_1, a_2, \dots, a_k 为一个答案数组,其中 aia_i 表示因数 did_i 首次出现的最小行号;若该因数在表中不存在,则 ai=0a_i = 0。

由于数组 aa 可能很长,首先输出一个整数 ss —— 即在 n×nn \times n 表中实际出现的 mm 的因数的个数。接着,输出单个值 X=a1⊕a2⊕⋯⊕akX = a_1 \oplus a_2 \oplus \dots \oplus a_k,其中 ⊕\oplus 表示按位异或运算。

输入输出样例

  • 输入#1

    3
    3 72 1
    10 10 15
    6 1 210

    输出#1

    6 2
    10 0
    8 5

说明/提示

In the first test case, m=72⋅1=72m = 72 \cdot 1 = 72 and has 1212 divisors [1,2,3,4,6,8,9,12,18,24,36,72][1, 2, 3, 4, 6, 8, 9, 12, 18, 24, 36, 72]. The 3×33 \times 3 multiplication table looks like that:

1

2

3

1

1

2

3

2

2

4

6

3

3

6

9

For each divisor of mm that is present in the table, the position with minimum row index is marked. So the array of answers aa is equal to [1,1,1,2,2,0,3,0,0,0,0,0][1, 1, 1, 2, 2, 0, 3, 0, 0, 0, 0, 0]. There are only 66 non-zero values, and xor of aa is equal to 22.

In the second test case, m=10⋅15=150m = 10 \cdot 15 = 150 and has 1212 divisors [1,2,3,5,6,10,15,25,30,50,75,150][1, 2, 3, 5, 6, 10, 15, 25, 30, 50, 75, 150]. All divisors except 7575 and 150150 are present in the 10×1010 \times 10 table. Array aa == [1,1,1,1,1,1,3,5,3,5,0,0][1, 1, 1, 1, 1, 1, 3, 5, 3, 5, 0, 0]. There are 1010 non-zero values, and xor of aa is equal to 00.

In the third test case, m=1⋅210=210m = 1 \cdot 210 = 210 and has 1616 divisors [1,2,3,5,6,7,10,14,15,21,30,35,42,70,105,210][1, 2, 3, 5, 6, 7, 10, 14, 15, 21, 30, 35, 42, 70, 105, 210]. The 6×66 \times 6 table with marked divisors is shown below:

1

2

3

4

5

6

1

1

2

3

4

5

6

2

2

4

6

8

10

12

3

3

6

9

12

15

18

4

4

8

12

16

20

24

5

5

10

15

20

25

30

6

6

12

18

24

30

36

Array aa == [1,1,1,1,1,0,2,0,3,0,5,0,0,0,0,0][1, 1, 1, 1, 1, 0, 2, 0, 3, 0, 5, 0, 0, 0, 0, 0]. There are 88 non-zero values, and xor of aa is equal to 55.

在第一个测试用例中,m=72⋅1=72m = 72 \cdot 1 = 72,它有 1212 个因数:[1,2,3,4,6,8,9,12,18,24,36,72][1, 2, 3, 4, 6, 8, 9, 12, 18, 24, 36, 72]。其 3×33 \times 3 乘法表如下所示:

1

2

3

1

1

2

3

2

2

4

6

3

3

6

9

对于 mm 的每个出现在该乘法表中的因数,我们标记其所在位置中行索引最小者。因此答案数组 aa 为 [1,1,1,2,2,0,3,0,0,0,0,0][1, 1, 1, 2, 2, 0, 3, 0, 0, 0, 0, 0]。其中仅有 66 个非零值,且 aa 的异或和为 22。

在第二个测试用例中,m=10⋅15=150m = 10 \cdot 15 = 150,它有 1212 个因数:[1,2,3,5,6,10,15,25,30,50,75,150][1, 2, 3, 5, 6, 10, 15, 25, 30, 50, 75, 150]。除 7575 和 150150 外,其余所有因数均出现在 10×1010 \times 10 乘法表中。数组 a=[1,1,1,1,1,1,3,5,3,5,0,0]a = [1, 1, 1, 1, 1, 1, 3, 5, 3, 5, 0, 0]。其中共有 1010 个非零值,且 aa 的异或和为 00。

在第三个测试用例中,m=1⋅210=210m = 1 \cdot 210 = 210,它有 1616 个因数:[1,2,3,5,6,7,10,14,15,21,30,35,42,70,105,210][1, 2, 3, 5, 6, 7, 10, 14, 15, 21, 30, 35, 42, 70, 105, 210]。带标记因数的 6×66 \times 6 乘法表如下所示:

1

2

3

4

5

6

1

1

2

3

4

5

6

2

2

4

6

8

10

12

3

3

6

9

12

15

18

4

4

8

12

16

20

24

5

5

10

15

20

25

30

6

6

12

18

24

30

36

数组 a=[1,1,1,1,1,0,2,0,3,0,5,0,0,0,0,0]a = [1, 1, 1, 1, 1, 0, 2, 0, 3, 0, 5, 0, 0, 0, 0, 0]。其中共有 88 个非零值,且 aa 的异或和为 55。

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

首页