Notice
Recent Posts
Recent Comments
Link
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
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
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Lennon FE

[๋ฐฑ์ค€ 1789๋ฒˆ] ์ˆ˜๋“ค์˜ ํ•ฉ - ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(nodejs) ๋ณธ๋ฌธ

๐Ÿ”ฅ Algorithm/Baekjoon

[๋ฐฑ์ค€ 1789๋ฒˆ] ์ˆ˜๋“ค์˜ ํ•ฉ - ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(nodejs)

Lennon 2022. 3. 14. 21:19
728x90
๋ฐ˜์‘ํ˜•

https://www.acmicpc.net/problem/1789

 

1789๋ฒˆ: ์ˆ˜๋“ค์˜ ํ•ฉ

์ฒซ์งธ ์ค„์— ์ž์—ฐ์ˆ˜ S(1 ≤ S ≤ 4,294,967,295)๊ฐ€ ์ฃผ์–ด์ง„๋‹ค.

www.acmicpc.net

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
let input;
rl.on('line', function (line) {
  input = +line;
  rl.close();
}).on('close', function () {
  let count = 0;
  let i = 1;

  while (count <= input) {
    count += i;
    i++;
  }

  console.log(i - 2);
});

๊ทธ๋ฆฌ๋””๋ผ ์ƒ๊ฐํ•˜๊ธฐ ๋‚˜๋ฆ„๋Œ€๋กœ ํ’€ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™๋‹ค.

๊ทธ๋ƒฅ ๋ฌธ์ œ๋งŒ ๋ณด๋ฉด ์–ด๋–ป๊ฒŒ ํ’€์–ด์•ผํ• ์ง€ ๋ง‰๋ง‰ํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, ์ƒ๊ฐํ•ด๋ณด๋ฉด ์—„์ฒญ ๊ฐ„๋‹จํ•˜๊ฒŒ ํ’€ ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์ด๋‹ค.

728x90
๋ฐ˜์‘ํ˜•
Comments