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

[๋ฐฑ์ค€][Node.js] 1748๋ฒˆ : ์ˆ˜ ์ด์–ด ์“ฐ๊ธฐ 1

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

 

 

Algorithm

-  ์ˆ˜ ์ด์–ด ์“ฐ๊ธฐ 1 -

 


 

๋ฌธ์ œ

1๋ถ€ํ„ฐ N๊นŒ์ง€์˜ ์ˆ˜๋ฅผ ์ด์–ด์„œ ์“ฐ๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ƒˆ๋กœ์šด ํ•˜๋‚˜์˜ ์ˆ˜๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค.

 

1234567891011121314151617181920212223...

 

์ด๋ ‡๊ฒŒ ๋งŒ๋“ค์–ด์ง„ ์ƒˆ๋กœ์šด ์ˆ˜๋Š” ๋ช‡ ์ž๋ฆฌ ์ˆ˜์ผ๊นŒ? ์ด์ˆ˜์˜ ์ž๋ฆฟ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

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

 

๋ฌธ์ œ ํ’€๊ธฐ

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 result = 0;
	let len = 1;
	let num = 10;

	for (let i = 1; i <= input; i++) {
		if (i % num === 0) {
			len++;
			num *= 10;
		}
		result += len;
	}
	console.log(result);
	process.exit();
});

 

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€