CF1846E1.Rudolf and Snowflakes (simple version)

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is a simple version of the problem. The only difference is that in this version n≤106n \le 10^6.

One winter morning, Rudolf was looking thoughtfully out the window, watching the falling snowflakes. He quickly noticed a certain symmetry in the configuration of the snowflakes. And like a true mathematician, Rudolf came up with a mathematical model of a snowflake.

He defined a snowflake as an undirected graph constructed according to the following rules:

  • Initially, the graph has only one vertex.
  • Then, more vertices are added to the graph. The initial vertex is connected by edges to kk new vertices (k>1k \gt 1).
  • Each vertex that is connected to only one other vertex is connected by edges to kk more new vertices. This step should be done at least once.

The smallest possible snowflake for k=4k = 4 is shown in the figure.

After some mathematical research, Rudolf realized that such snowflakes may not have any number of vertices. Help Rudolf check if a snowflake with nn vertices can exist.

这是一个该问题的简化版本,唯一的区别在于本版本中 n≤106n \le 10^6。

一个冬日清晨,鲁道夫若有所思地望着窗外,观察着飘落的雪花。他很快注意到雪花构型中存在某种对称性。作为一名真正的数学家,鲁道夫据此提出了雪花的数学模型。

他将雪花定义为一个按如下规则构造的无向图:

  • 初始时,图中仅含一个顶点;
  • 随后向图中添加更多顶点:初始顶点与 kk 个新顶点(k>1k > 1)分别连边;
  • 每个仅与一个其他顶点相邻的顶点,均需再与 kk 个新顶点分别连边;此步骤至少执行一次。

当 k=4k = 4 时,最小可能的雪花如图所示。

经过一些数学研究,鲁道夫意识到此类雪花的顶点数并非任意正整数均可取。请帮助鲁道夫判断:是否存在一个含 nn 个顶点的雪花。

输入格式

The first line of the input contains an integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

Then follow the descriptions of the test cases.

The first line of each test case contains an integer nn (1≤n≤1061 \le n \le 10^6) — the number of vertices for which it is necessary to check the existence of a snowflake.

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

随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1061 \le n \le 10^6)—— 需要检查是否存在雪花结构的顶点数量。

输出格式

Output tt lines, each of which is the answer to the corresponding test case — "YES" if there exists such k>1k \gt 1 for which a snowflake with the given number of vertices can be constructed; "NO" otherwise.

输出 tt 行,每行对应一个测试用例的答案:若存在满足 k>1k \gt 1 的整数 kk,使得能够构造出具有给定顶点数的雪花图形,则输出 "YES";否则输出 "NO"。

输入输出样例

  • 输入#1

    9
    1
    2
    3
    6
    13
    15
    255
    10101
    1000000

    输出#1

    NO
    NO
    NO
    NO
    YES
    YES
    YES
    YES
    NO

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

首页