Advertisement
TzvetanIG

Trailing Zeroes in N! - ver 2

Mar 23rd, 2014
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | None | 0 0
  1. using System;
  2.  
  3. class TrailingZeroesInNFactorial
  4. {
  5.     static void Main()
  6.     {
  7.         long n = long.Parse(Console.ReadLine());
  8.         long countZero = 0;
  9.  
  10.         for (int i = 1; i <= n; i++)
  11.         {
  12.             if (i % 5 == 0)
  13.             {
  14.                    countZero+= GetFive(i);
  15.             }
  16.         }
  17.  
  18.         Console.WriteLine(countZero);
  19.     }
  20.  
  21.  
  22.     static int GetFive(long number)
  23.     {
  24.         int count = 0;
  25.         while (number % 5 == 0)
  26.         {
  27.             number = number / 5;
  28.             count++;
  29.         }
  30.         return count++;
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement