Ad

The factorial of a positive integer n, denoted by n!, is the product of all positive integers less then or equal than to n:

n! = n(n-1)(n-2)...(2)(1)

5! = (5)(4)(3)(2)(1) = 120

By convenction, 0! equals to 1.

Calculate the initial number of a given facturial result.

https://en.wikipedia.org/wiki/Factorial

Code
Diff
  • using System;
    
        public static class ReverseFactorial
        {
            public static int Kata(long n)
            {
              if(n == 0) return 1;
              for (long i = 2; n / i > 1; i++)
              {
                n /= i;
              }
              return (int) n;
            }
        }
    • using System;
    • public static class RecursiveFactorials
    • public static class ReverseFactorial
    • {
    • public static int Kata(long n)
    • {
    • int i = 1;
    • if (n != 0)
    • {
    • while (n / i != 1)
    • {
    • n /= i;
    • i++;
    • }
    • } else
    • {
    • n = i;
    • }
    • return (int) n;
    • if(n == 0) return 1;
    • for (long i = 2; n / i > 1; i++)
    • {
    • n /= i;
    • }
    • return (int) n;
    • }
    • }