-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1024.js
More file actions
32 lines (29 loc) · 744 Bytes
/
1024.js
File metadata and controls
32 lines (29 loc) · 744 Bytes
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
32
/*
sum(i, i+1, i+2, ..., i+k-1)
= i*k + k(k-1)/2
= N
k는 L 이상 100 이하
k=L부터 100까지 돌면서 이 식을 만족하는 i가 있는지 찾기
*/
const INPUT_FILE = process.platform === 'linux' ? 'dev/stdin' : './input';
const [sum, minLength] = require('fs')
.readFileSync(INPUT_FILE)
.toString()
.trim()
.split(' ')
.map(Number);
let length;
let start = -1;
for (length = minLength; length <= 100; length += 1) {
const equation = sum - (length * (length - 1)) / 2;
if (equation >= 0 && equation % length === 0) {
start = equation / length;
break;
}
}
if (start === -1) {
console.log(-1);
} else {
const sol = Array.from({ length }).map((_, idx) => start + idx);
console.log(sol.join(' '));
}