Problem · Math

Find Sequences

MediumTrend MicroOA

Given a number n (1 <= n <= 1010), the task is to find all the possible sequences of successive positive integer numbers (p, p+1, ..., p+m) that satisfy the equation: n = p^2 + (p+1)2 + ... + (p+m)2.

Input

The input consists of a single integer n.

Output

The output is an array of strings consisting of two parts. The first element should display the total number of possible sequences, denoted as k. The following k elements should contain the descriptions of the sequences. Each element is a string starts with the count of numbers in the corresponding sequence, denoted as c, followed by c integers representing the successive positive integer numbers, separated by a space. These k elements should be ordered in descending order of C.

Examples
01 · Example 1
n = 2030
return = ["2", "4 21 22 23 24", "3 25 26 27"]
An explanation based on EDUCATED GUESS:::

There are two sequences that satisfy the equation for n = 2030:

1. The sequence starting with p = 21 and having 4 numbers: 21, 22, 23, 24. The sum of their squares is 21^2 + 22^2 + 23^2 + 24^2 = 2030.

2. The sequence starting with p = 25 and having 3 numbers: 25, 26, 27. The sum of their squares is 25^2 + 26^2 + 27^2 = 2030.

Therefore, the output is ["2", "4 21 22 23 24", "3 25 26 27"], with the total number of sequences 2 followed by the sequences in descending order of the count of numbers.

Constraints
🐻
More Trend Micro problems
drafts saved locally
public String[] findSequences(long n) {
  // write your code here
}
n2030
expected["2", "4 21 22 23 24", "3 25 26 27"]
sign in to submit