Factorial (mind the size) · 阶乘(注意大小)
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
English
Factorial (mind the size)
n! is 1 × 2 × … × n, and 0! is 1. It grows fast — 20! is over two billion billion — so the method returns a long, not an int, or the answer would overflow. Multiply from 2 up to n.
中文
阶乘(注意大小)
n! 是 1 × 2 × … × n,而 0! 是 1。它增长很快 —— 20! 超过两百亿亿 —— 所以这个方法返回 long 而不是 int,否则结果会溢出。从 2 乘到 n。
Complete factorial(int n) returning n! as a long (so large values fit). factorial(0) is 1. Assume 0 <= n <= 20. · 完成 factorial(int n),以 long 返回 n!(让较大的值放得下)。factorial(0) 是 1。假设 0 <= n <= 20。
Click Run to see the output here. · 点击“运行”查看此处输出。