Problem 44334. Sums of Multiple Pairs of Triangular Numbers
This is a follow-up to Problem 44289 - Find two triangular numbers whose sum is input.
There are some numbers that are the sum of multiple pairs of triangular numbers. For example, 81 = 36+45 = 15+66 = 3+78. Given a number X, find all of the possible pairs of triangular numbers that add up to X. Your answer should be in a 2-by-X matrix. Each column of the matrix should sum to X, and each pair of triangular numbers should only appear once. The top row sorted from low to high. The output for 81 would be:
[ 3 15 36 78 66 45]
Good luck!
Solution Stats
Problem Comments
-
1 Comment
The first test case is wrong 0 and 21 are triangular numbers too (https://oeis.org/A000217), therefore:
multi_triangular(21)
[ 0, 6;
21, 15]
PS: And 0 does not make a pair with every number in this case.
Solution Comments
Show commentsProblem Recent Solvers236
Suggested Problems
-
Given an unsigned integer x, find the largest y by rearranging the bits in x
1820 Solvers
-
Project Euler: Problem 1, Multiples of 3 and 5
3168 Solvers
-
654 Solvers
-
310 Solvers
-
Convert given decimal number to binary number.
2069 Solvers
More from this Author80
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!