10
Given the sequence OEIS A033581, which is the infinite sequence, the n'th term (0-indexing) is given by the closed form formula 6 × n2 .
Your task is to write code, which outputs all the subsets of the set of N first numbers in the sequence, such that the sum of the subset is a perfect square.
Rules
- The integer
N
is given as input. - You cannot reuse a number already used in the sum. (that is, each number can appear in each subset at most once)
- Numbers used can be non-consecutive.
- Code with the least size wins.
Example
The given sequence is {0,6,24,54,96,...,15000}
One of the required subsets will be {6,24,294}, because
6+24+294 = 324 = 18^2
You need to find all such sets of all possible lengths in the given range.
3
Good first post! You may consider adding examples and test cases. For future reference, we have a sandbox that you can trial your ideas in.
– Οurous – 2018-01-09T05:53:50.677Is this asking us to calculate A033581 given N? Or am I not understanding this correctly? – ATaco – 2018-01-09T06:14:16.830
@ATaco Like for a sequence (1,9,35,39...) 1+9+39=49 a perfect square (It uses 3 numbers), 35+1= 36 another perfect square but it uses 2 numbers. So {1,35} is the required set. – prog_SAHIL – 2018-01-09T06:17:32.113
3@prog_SAHIL Adding that, and a few more, as examples to the post would be helpful :) – Οurous – 2018-01-09T06:25:20.520
Let us continue this discussion in chat.
– prog_SAHIL – 2018-01-09T08:12:31.317