Decimal factorial(int n) { Decimal result = Decimal.one; for (int i = 2; i <= n; i++) { result *= Decimal.fromInt(i); } return result; }