VelizarAvramov

14. Factorial Trailing Zeroes

Nov 25th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4. namespace _14_Fatorial_Trailing_Zeroes
  5. {
  6.     class FactorialTrailingZeroes
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             BigInteger n = BigInteger.Parse(Console.ReadLine());
  11.  
  12.             BigInteger factorial = FindFactorial(n);
  13.             BigInteger zeroes = FindZeroes(factorial);
  14.             //Console.WriteLine(factorial);
  15.             Console.WriteLine(zeroes);
  16.  
  17.         }
  18.  
  19.         private static BigInteger FindZeroes(BigInteger factorial)
  20.         {
  21.             int count = 0;
  22.             while (factorial != 0)
  23.             {
  24.                 BigInteger digit = factorial % 10;
  25.                 if (digit == 0)
  26.                 {
  27.                     count++;
  28.                 }
  29.                 else
  30.                 {
  31.                     break;
  32.                 }
  33.                 factorial /= 10;
  34.             }
  35.             return count;
  36.         }
  37.  
  38.         private static BigInteger FindFactorial(BigInteger n)
  39.         {
  40.             BigInteger factorial = 1;
  41.             for (int i = 1; i <= n; i++)
  42.             {
  43.                 factorial *= i;
  44.             }
  45.             return factorial;
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment