Factorial (mind the size) · Factorielle (attention à la taille)
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.
Factorielle (attention à la taille)
n! est 1 × 2 × … × n, et 0! est 1. Cela croît vite — 20! dépasse deux milliards de milliards — donc la méthode retourne un long, pas un int, sinon la réponse déborderait. Multipliez de 2 jusqu'à n.
Complete factorial(int n) returning n! as a long (so large values fit). factorial(0) is 1. Assume 0 <= n <= 20. · Complétez factorial(int n) retournant n! comme long (pour que les grandes valeurs tiennent). factorial(0) est 1. Supposez 0 <= n <= 20.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.