/*
This program computes the factorial of numbers greater than 20.
TypeScript (and JavaScript) provide BigInt, an arbitrary‑precision
integer type that can represent extremely large numbers safely.
*/
/*
Compute factorial using BigInt.
The algorithm multiplies numbers from 2 to n.
BigInt handles overflow internally and grows as needed.
*/
function factorialBig(n: bigint): bigint {
let result: bigint = 1n;
for (let i: bigint = 2n; i <= n; i++) {
result *= i;
}
return result;
}
/*
Read a line from stdin and return it as a string.
*/
function readInput(): Promise<string> {
return new Promise(resolve => {
process.stdin.once("data", data => resolve(data.toString().trim()));
});
}
/*
Main entry point: read input, compute factorial, print result.
*/
async function main(): Promise<void> {
process.stdout.write("Enter a number greater than 20: ");
const input: string = await readInput();
const n: bigint = BigInt(input);
const result: bigint = 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
*/