CF2162G.Beautiful Tree

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A tree is a connected graph without cycles.

A tree is called beautiful if the sum of the products of the vertex labels for all its edges is a perfect square.

More formally, let EE be the set of edges in the tree. The tree is called beautiful if the value $$S = \sum_{\{u, v\} \in E} (u \cdot v)$$ is a perfect square. That is, there exists an integer xx such that S=x2S = x^2.

You are given an integer nn. Your task is to construct a beautiful tree having nn vertices or report that such a tree does not exist.

树是无环的连通图。

若一棵树的所有边的两个端点标签乘积之和为完全平方数,则称该树为“优美的”。

更准确地说,设 EE 为该树的边集。若值

S=∑{u,v}∈E(u⋅v)S = \sum_{\{u, v\} \in E} (u \cdot v)

为完全平方数,则称该树为优美的。即存在整数 xx,使得 S=x2S = x^2。

给定一个整数 nn,你的任务是构造一棵含 nn 个顶点的优美树;若不存在这样的树,则报告不存在。

输入格式

The first line of input contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of testcases.

Each testcase contains a single integer nn (2≤n≤2⋅1052 \le n \le 2\cdot10^5).

It is guaranteed that the sum of nn over all the testcases does not exceed 2⋅1052\cdot10^5.

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。

每个测试用例包含一个整数 nn(2≤n≤2⋅1052 \le n \le 2\cdot10^5)。

保证所有测试用例中 nn 的总和不超过 2⋅1052\cdot10^5。

输出格式

For each testcase, if there is no beautiful tree having nn vertices, print −1-1.

Otherwise, print n−1n-1 lines denoting the edges of a beautiful tree having nn vertices. Each line should contain two space-separated integers u,vu,v (1≤u,v≤n1 \le u,v \le n) representing an edge.

The vertices can be printed in any order within an edge, and the edges can be printed in any order.

对于每个测试用例,如果不存在包含 nn 个顶点的优美树,则输出 −1-1。

否则,输出 n−1n-1 行,每行表示一棵包含 nn 个顶点的优美树的一条边。每行应包含两个以空格分隔的整数 u,vu,v(1≤u,v≤n1 \le u,v \le n),表示一条边。

每条边中两个顶点的顺序可以任意,各条边的输出顺序也可以任意。

输入输出样例

  • 输入#1

    3
    2
    3
    4

    输出#1

    -1
    1 3
    2 3
    1 2
    3 1
    4 1

说明/提示

Test case 1: No beautiful tree exists with 22 vertices. Hence, print −1-1.

Test case 2:

S=(2⋅3)+(1⋅3)=9=(3)2S = (2\cdot3) + (1\cdot3) = 9 = (3)^2

Test case 3:

S=(2⋅1)+(3⋅1)+(4⋅1)=9=(3)2S = (2\cdot1) + (3\cdot1) + (4\cdot1) = 9 = (3)^2

测试用例 1:不存在包含 22 个顶点的优美树。因此,输出 −1-1。

测试用例 2:

S=(2⋅3)+(1⋅3)=9=(3)2S = (2\cdot3) + (1\cdot3) = 9 = (3)^2

测试用例 3:

S=(2⋅1)+(3⋅1)+(4⋅1)=9=(3)2S = (2\cdot1) + (3\cdot1) + (4\cdot1) = 9 = (3)^2

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

首页