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

[๋ฐฑ์ค€][Node.js] 1676๋ฒˆ : ํŒฉํ† ๋ฆฌ์–ผ 0์˜ ๊ฐœ์ˆ˜

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

 

 

Algorithm

-  ํŒฉํ† ๋ฆฌ์–ผ 0์˜ ๊ฐœ์ˆ˜ -

 


 

๋ฌธ์ œ

N!์—์„œ ๋’ค์—์„œ๋ถ€ํ„ฐ ์ฒ˜์Œ 0์ด ์•„๋‹Œ ์ˆซ์ž๊ฐ€ ๋‚˜์˜ฌ ๋•Œ๊นŒ์ง€ 0์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

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

 

๋ฌธ์ œ ํ’€๊ธฐ

const readline = require("readline");
const rl = readline.createInterface({
	input: process.stdin,
	output: process.stdout,
});
let input = 0;
rl.on("line", function (line) {
	input = +line.toString();
}).on("close", function () {
	let value =
		input === 0 ? "1" : String(factorial(input)).split("").reverse();
	let count = 0;
	for (let i = 0; i < value.length; i++) {
		if (value[i] === "0") count++;
		else break;
	}
	console.log(count);
	process.exit();
});

let factorial = (num) => {
	if (num === 0) return 1n;

	return BigInt(num) * factorial(num - 1);
};

 

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€