A - Sum of Reciprocals of Squares Editorial by evima
Call a sequence of positive integers \(A=(A_1,A_2,\ldots,A_n)\) of length \(n\) a good sequence if it satisfies \(\displaystyle\sum_{i=1}^n\frac1{A_i^2}=1\).
First, by trying all small cases, we can find that the answer is No for \(N=2,3,5\).
If an integer sequence \(A=(A_1,A_2,\ldots,A_N)\) of length \(N\) is a good sequence, then \(A'=(A_2,A_3,\ldots,A_N,2A_1,2A_1,2A_1,2A_1)\) is also a good sequence.
Using this fact, we can see that if we can make small cases for \(N=1,6,8\), we can recursively construct \(A\) from them.
For these cases, the following satisfy the conditions:
- \(N=1\): \(A=(1)\)
- \(N=6\): \(A=(2,2,2,3,3,6)\)
- \(N=8\): \(A=(2,2,3,3,3,3,6,6)\)
Using these as base cases, we can construct solutions in order.
By implementing the above appropriately, you can solve this problem.
Implementation example (Python3)
import sys
from collections import deque
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
if n in [2, 3, 5]:
print("No")
continue
if n % 3 == 0:
a = deque([2, 2, 2, 3, 3, 6])
elif n % 3 == 1:
a = deque([1])
else:
a = deque([2, 2, 3, 3, 3, 3, 6, 6])
while len(a) < n:
x = a.popleft()
for i in range(4):
a.append(2 * x)
ans = list(a)
print("Yes")
print(*ans)
posted:
last update: