๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ์ธ๊ณต๋ถ€/Algorithm

[๋ฐฑ์ค€][Node.js] 2292๋ฒˆ : ๋ฒŒ์ง‘

by ๐Ÿ‡๋ฐ•๋ด‰๋ด‰๐Ÿ‡ 2021. 7. 30.

 

 

Algorithm

-  ๋ฒŒ์ง‘ -

 

 


 

๋ฌธ์ œ

์œ„์˜ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด ์œก๊ฐํ˜•์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฒŒ์ง‘์ด ์žˆ๋‹ค. ๊ทธ๋ฆผ์—์„œ ๋ณด๋Š” ๋ฐ”์™€ ๊ฐ™์ด ์ค‘์•™์˜ ๋ฐฉ 1๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด์„œ ์ด์›ƒํ•˜๋Š” ๋ฐฉ์— ๋Œ์•„๊ฐ€๋ฉด์„œ 1์”ฉ ์ฆ๊ฐ€ํ•˜๋Š” ๋ฒˆํ˜ธ๋ฅผ ์ฃผ์†Œ๋กœ ๋งค๊ธธ ์ˆ˜ ์žˆ๋‹ค. ์ˆซ์ž N์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, ๋ฒŒ์ง‘์˜ ์ค‘์•™ 1์—์„œ N๋ฒˆ ๋ฐฉ๊นŒ์ง€ ์ตœ์†Œ ๊ฐœ์ˆ˜์˜ ๋ฐฉ์„ ์ง€๋‚˜์„œ ๊ฐˆ ๋•Œ ๋ช‡ ๊ฐœ์˜ ๋ฐฉ์„ ์ง€๋‚˜๊ฐ€๋Š”์ง€(์‹œ์ž‘๊ณผ ๋์„ ํฌํ•จํ•˜์—ฌ)๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด, 13๊นŒ์ง€๋Š” 3๊ฐœ, 58๊นŒ์ง€๋Š” 5๊ฐœ๋ฅผ ์ง€๋‚œ๋‹ค.

 

์ž…์ถœ๋ ฅ ์˜ˆ์‹œ

 

๋ฌธ์ œ ํ’€๊ธฐ

const readline = require("readline");
const rl = readline.createInterface({
	input: process.stdin,
	output: process.stdout,
});
let input;
rl.on("line", function (line) {
	input = +line.toString();
}).on("close", function () {
	let count = [0];
	let bee = [1];
	while (true) {
		if (input <= bee[bee.length - 1]) {
			break;
		}
		count.push(count[count.length - 1] + 6);
		bee.push(count[count.length - 1] + bee[bee.length - 1]);
	}
	console.log(bee.length);
	process.exit();
});

 

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€