Іван,
<pre id="out"></pre>
<script>
function fn(all) {
if (all % 4) return;
let m = all / 4 - 1;
if (m < 3) return;
const arr = [];
for (let b = 1; b < m; b++) {
for (let v = 1; v < m; v++) {
if(b + v > m) continue;
for (let n = 1; n < m; n++) {
let s = (b + v + n) * 4;
if (s == all) arr.push([b, v, n])
}
}
}
return arr
}
out.append(JSON.stringify(fn(40))
)
</script>