/*
This program computes the factorial of numbers greater than 20.
JavaScript's BigInt type supports arbitrary‑precision integers,
making it ideal for very large factorials.
*/
/*
Compute factorial using BigInt.
The algorithm multiplies numbers from 2 to n.
BigInt handles overflow internally and grows as needed.
*/
function factorialBig(n) {
let result = 1n; // BigInt literal
for (let i = 2n; i <= n; i++) {
result *= i;
}
return result;
}
/*
Main entry point: read input, compute factorial, print result.
*/
async function main() {
process.stdout.write("Enter a number greater than 20: ");
// Read input from stdin
const input = await new Promise(resolve =>
process.stdin.once("data", d => resolve(d.toString().trim()))
);
const n = BigInt(input);
const result = factorialBig(n);
console.log(`\nFactorial of ${n} is:\n`);
console.log(result.toString());
}
main();
/*
run:
Enter a number greater than 20: 25
Factorial of 25 is:
15511210043330985984000000
*/