난 이제 지쳤어요 땡벌 떙벌🐝
https://www.acmicpc.net/problem/2309
const INPUT = require("fs")
.readFileSync(process.platform === "linux" ? "/dev/stdin" : "./input.txt")
.toString()
.trim()
.split(" ");
function solution() {
const input = Number(INPUT);
const seq = 6;
const arr = [1];
let idx = 1;
while (true) {
const curValue = arr[arr.length - 1];
if (input > curValue) {
arr.push(curValue + seq * idx++);
} else {
break;
}
}
console.log(arr.length);
}
solution();
1,6,12,18 등 6n 만큼 증가하니까
1 -> 1
1~6 -> 7
1~6~12 -> 19
1~6~12~18 -> 37
이런식으로 찾고자 하는 숫자가 해당 범위 안에 있다면 array의 length가 1부터의 N까지 거리를 의미한다.
따라서 13은 7과 19 사이에 있으므로 3이 되는 것이다 :)
:)