#P2765. 魔术球问题
魔术球问题
Description
Assume there are rods. We insert balls labeled , , , ... into these rods in order, following the rules below:
- Each time, you can only place a ball on the top of some rod.
- On the same rod, the sum of the labels of any adjacent balls is a perfect square.
Design an algorithm to compute the maximum number of balls that can be placed on rods. For example, with rods, at most balls can be placed.
Given , compute the maximum number of balls that can be placed on rods.
Input Format
There is only one line containing an integer , representing the number of rods.
Output Format
This problem has a Special Judge.
Please output the maximum number of balls that can be placed on rods, along with a corresponding placement scheme.
The first line is the number of balls.
The next lines each contain several integers, representing the labels of the balls on one rod, separated by a single space.
4
11
1 8
2 7 9
3 6 10
4 5 11
Hint
Constraints
For of the testdata, it is guaranteed that .
Translated by ChatGPT 5
京公网安备 11011102002149号