In an Alten Nederland engineering tool, implement a reusable function that computes the factorial of a non-negative integer. The function must avoid Python's built-in factorial implementation and must support large values without relying on recursion depth.
For an integer n, factorial is defined as n! = 1 * 2 * ... * n, with 0! = 1. If an optional positive modulo is provided, return n! % modulo instead of the exact factorial.
Implement factorial(n, modulo=None).
n, a non-negative integer, and optional modulo, a positive integer or None.n! or its remainder modulo modulo.math.factorial or recursion in the primary solution.def factorial(n, modulo=None):