CF1662H.Boundary

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Bethany would like to tile her bathroom. The bathroom has width ww centimeters and length ll centimeters. If Bethany simply used the basic tiles of size 1×11 \times 1 centimeters, she would use w⋅lw \cdot l of them.

However, she has something different in mind.

  • On the interior of the floor she wants to use the 1×11 \times 1 tiles. She needs exactly (w−2)⋅(l−2)(w-2) \cdot (l-2) of these.
  • On the floor boundary she wants to use tiles of size 1×a1 \times a for some positive integer aa. The tiles can also be rotated by 9090 degrees.

For which values of aa can Bethany tile the bathroom floor as described? Note that aa can also be 11.

贝丝妮想用瓷砖铺满她的浴室。浴室的宽度为 ww 厘米,长度为 ll 厘米。如果贝丝妮仅使用基本的 1×11 \times 1 厘米瓷砖,则总共需要 w⋅lw \cdot l 块。

然而,她另有打算:

  • 在地板内部区域,她打算使用 1×11 \times 1 的瓷砖,恰好需要 (w−2)⋅(l−2)(w-2) \cdot (l-2) 块;
  • 在地板边界区域,她打算使用尺寸为 1×a1 \times a 的瓷砖(其中 aa 为某个正整数),且这些瓷砖可沿 90∘90^\circ 方向旋转。

对于哪些 aa 的取值,贝丝妮能按上述方式铺满整个浴室地板?注意:aa 也可以等于 11。

输入格式

Each test contains multiple test cases. The first line contains an integer tt (1≤t≤1001\le t\le 100) — the number of test cases. The descriptions of the tt test cases follow.

Each test case consist of a single line, which contains two integers ww, ll (3≤w,l≤1093 \leq w, l \leq 10^{9}) — the dimensions of the bathroom.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1001\le t\le 100),表示测试用例的数量。接下来是 tt 个测试用例的描述。

每个测试用例由一行组成,包含两个整数 ww、ll(3≤w,l≤1093 \leq w, l \leq 10^{9}),表示浴室的尺寸。

输出格式

For each test case, print an integer kk (0≤k0\le k) — the number of valid values of aa for the given test case — followed by kk integers a1,a2,…,aka_1, a_2,\dots, a_k (1≤ai1\le a_i) — the valid values of aa. The values a1,a2,…,aka_1, a_2, \dots, a_k have to be sorted from smallest to largest.

It is guaranteed that under the problem constraints, the output contains at most 200 000200\,000 integers.

对于每个测试用例,输出一个整数 kk(0≤k0\le k)—— 表示该测试用例下合法的 aa 值的个数 —— 然后输出 kk 个整数 a1,a2,…,aka_1, a_2,\dots, a_k(1≤ai1\le a_i)—— 即所有合法的 aa 值。这些值 a1,a2,…,aka_1, a_2, \dots, a_k 必须按从小到大的顺序排列。

在本题约束条件下,保证输出中整数的总数不超过 200 000200\,000 个。

输入输出样例

  • 输入#1

    3
    3 5
    12 12
    314159265 358979323

    输出#1

    3 1 2 3
    3 1 2 11
    2 1 2

说明/提示

In the first test case, the bathroom is 33 centimeters wide and 55 centimeters long. There are three values of aa such that Bethany can tile the floor as described in the statement, namely a=1a=1, a=2a=2 and a=3a=3. The three tilings are represented in the following pictures.

在第一个测试用例中,浴室宽 33 厘米、长 55 厘米。存在三个满足题干所述条件的 aa 值,使得贝丝妮能够按要求铺满地面,即 a=1a=1、a=2a=2 和 a=3a=3。这三种铺法如以下图片所示。

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

首页