Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Write a program that calculates with how many zeroes the factorial of a given number N has at its end.
- Your program should work well for very big numbers, e.g. N = 100000.
- 5^1 : 4617 ÷ 5 = 923.4, so I get 923 factors of 5
- 5^2 : 4617 ÷ 25 = 184.68, so I get 184 additional factors of 5
- 5^3 : 4617 ÷ 125 = 36.936, so I get 36 additional factors of 5
- 5^4 : 4617 ÷ 625 = 7.3872, so I get 7 additional factors of 5
- 5^5 : 4617 ÷ 3125 = 1.47744, so I get 1 more factor of 5
- 5^6 : 4617 ÷ 15625 = 0.295488, which is less than 1, so I stop here.
- Then 4617! has 923 + 184 + 36 + 7 + 1 = 1151 trailing zeroes.
- http://www.purplemath.com/modules/factzero.htm
- */
- using System;
- class TrailingZeroes
- {
- static void Main()
- {
- int number = int.Parse(Console.ReadLine());
- int count = 1, sumZeroes = 0, truncated = 0;
- do
- {
- truncated = (int)Math.Truncate(number / Math.Pow(5, count));
- sumZeroes += truncated;
- count++;
- }
- while ((truncated) >= 1);
- Console.WriteLine(sumZeroes);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement