cswork / OA打开练习工作台

Trend MicroOA #3

Find Sequences

估计中等可在线判题

考点(AI 标注)双指针滑窗位运算

Given a positive integer n, find all non-empty sequences of consecutive positive integers p, p+1, …, p+c−1 whose c squares sum to n. p≥1 and c≥1, and single-term sequences must be output as well. Output all sequences in decreasing order of their number of terms c. There is at most one sequence of each length, so this order is unique. The fixed original body text fully specifies 1≤n≤10^10; this site restores from the original HTML the rules and range that the compiled version's parser swallowed, and converts the original returned string array into line-by-line output.

输入格式

One line with a positive integer n, 1≤n≤10000000000.

输出格式

The first line contains the total number of sequences k. Each of the next k lines first gives the sequence's number of terms c, then all c of its consecutive positive integers, separated by spaces. Output the lines in decreasing order of c. If there is no solution, output only one line containing 0. Output the elements themselves, not their squares.

样例 1

输入:

1

输出:

1
1 1

样例 2

输入:

2

输出:

0

样例 3

输入:

25

输出:

2
2 3 4
1 5

样例说明

For n=1 there is only [1]; n=2 has no solution; n=25 has 3²+4²=25 and 5²=25, so the longer [3,4] is output before [5].