_CodeBehind

14. Factorial Trailing Zeroes

Jan 22nd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. using System;
  2.  
  3. using System.Numerics;
  4.  
  5. namespace Factorial_Trailing_Zeroes
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. BigInteger numberInt = BigInteger.Parse(Console.ReadLine());
  12. BigInteger result = numberInt;
  13.  
  14. for (BigInteger i = 1; i < numberInt; i++)
  15. {
  16. result = result * i;
  17. }
  18. Console.WriteLine(findTrailingZeros(numberInt) );
  19.  
  20. }
  21. static BigInteger findTrailingZeros(BigInteger number)
  22. {
  23. BigInteger countZeroes = 0;
  24. for (BigInteger divider = 5; number / divider >= 1; divider *= 5)
  25. {
  26. countZeroes += number / divider;
  27. }
  28. return countZeroes;
  29. }
  30. }
  31. }
Add Comment
Please, Sign In to add comment