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);
};
๋ฐ์ํ
'๊ฐ์ธ๊ณต๋ถ > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค][Node.js] 1712๋ฒ : ์์ต๋ถ๊ธฐ์ (0) | 2021.07.14 |
---|---|
[๋ฐฑ์ค][Node.js] 1697๋ฒ : ์จ๋ฐ๊ผญ์ง (0) | 2021.07.12 |
[๋ฐฑ์ค][Node.js] 1620๋ฒ : ํฌ์ผ๋ชฌ ๋ง์คํฐ ์ด๋ค์ (0) | 2021.07.10 |
[๋ฐฑ์ค][Node.js] 1550๋ฒ : 16์ง์ (0) | 2021.07.09 |
[๋ฐฑ์ค][Node.js] 1547๋ฒ : ๊ณต (0) | 2021.07.08 |
๋๊ธ