AT_arc220_a.Sum of Reciprocals of Squares

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given a positive integer NN.

Determine whether there exists a sequence of positive integers A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N) satisfying all of the following conditions, and if so, find one such sequence.

  • 1≤Ai≤1061\le A_i\le 10^6
  • ∑i=1N1Ai2=1\displaystyle \sum_{i=1}^N \frac1{A_i^2}=1

You are given TT test cases; solve each of them.

给定一个正整数 NN。

判断是否存在一个由正整数组成的序列 A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N),满足以下所有条件;若存在,请构造出一个这样的序列。

  • 1≤Ai≤1061\le A_i\le 10^6
  • ∑i=1N1Ai2=1\displaystyle \sum_{i=1}^N \frac1{A_i^2}=1

你将得到 TT 组测试用例,请对每组用例求解。

输入格式

The input is given from Standard Input in the following format:

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

Each test case is given in the following format:

NN

输入从标准输入给出,格式如下:

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

每个测试用例的格式如下:

NN

输出格式

Output the answers for the test cases in order, separated by newlines.

For each test case, if no AA satisfying all conditions exists, output No.

If an AA satisfying all conditions exists, output it in the following format:

Yes
A1A_1 A2A_2 …\ldots ANA_N

If multiple AA satisfying all conditions exist, any of them will be accepted.

按测试用例的顺序输出答案,每个答案之间用换行符分隔。

对于每个测试用例,若不存在满足所有条件的 AA,则输出 No。

若存在满足所有条件的 AA,则按以下格式输出:

Yes
A1A_1 A2A_2 …\ldots ANA_N

若存在多个满足条件的 AA,输出其中任意一个即可。

输入输出样例

  • 输入#1

    4
    4
    2
    1
    17

    输出#1

    Yes
    2 2 2 2
    No
    Yes
    1
    Yes
    2 2 3 3 4 4 5 5 6 7 10 14 20 20 21 30 30

说明/提示

Sample 1 Explanation:
Consider the first test case.

For A=(2,2,2,2)A=(2,2,2,2), we have ∑i=1N1Ai2=14+14+14+14=1\displaystyle \sum_{i=1}^N\frac1{A_i^2}=\frac14+\frac14+\frac14+\frac14=1, so we can confirm that the conditions are satisfied.

Constraints

  • 1≤T≤5001\le T\le 500
  • 1≤N≤1051\le N\le 10^5
  • The sum of NN over all test cases is at most 10510^5.
  • All input values are integers.

样例 1 解释:
考虑第一个测试用例。

对于 A=(2,2,2,2)A=(2,2,2,2),有 ∑i=1N1Ai2=14+14+14+14=1\displaystyle \sum_{i=1}^N\frac1{A_i^2}=\frac14+\frac14+\frac14+\frac14=1,因此可以确认条件满足。

限制条件

  • 1≤T≤5001\le T\le 500
  • 1≤N≤1051\le N\le 10^5
  • 所有测试用例的 NN 之和不超过 10510^5。
  • 所有输入值均为整数。

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

首页