# 4. 用连续自然数之和来表达整数

4 4-1

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', (input) => {
    let target = parseInt(input);
    console.log(target + '=' + target);

    const expressions = [];
    for(let i=1; i<targe; i++) {
        let sum = 0;
        let expression = '';
        for(let j=i; j<target; j++) {
            sum += j;
            expression += j + '+';
            if (sum === target) {
                expressions.push(target + '=' + expression.slice(0, -1));
                break;
            }
        }
    }

    expressions.sort((s1, s2) => s1.length - s2.length);
    expressions.forEach(expression => console.log(expression));
    console.log('Result:' + (expressions.length + 1));

    rl.close();
})

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31