Input a positive integer n, how many 0s are at the end of n! (ie factorial)? For example: n = 10; n! = 3628800, so the answer is 2
Enter description:
Input is one line, n(1 ≤ n ≤ 1000)
Output description:
Output an integer, that is, what the question requires
Example 1
enter
10
output
2
#include <iostream> using namespace std; intmain() { int n, k = 0; cin >> n; while(n) { k = n / 5 + k; n = n / 5; } cout << k; return 0; }Explanation: For example, 100/5=20, that is, there are 20 numbers that contain factor 5: 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85,90,95,100. Among these 20 numbers, there are 20/5=4 containing factors 5: 25, 50, 75, 100 (the first 20 numbers can be regarded as 5*1, 5*2, 5*3, 5*4, 5* 5, 5*6, 5*7, 5*8, 5*9, 5*10, 5*11, 5,12, 5*13, 5*14, 5*15, 5*16, 5*17 , 5*18, 5*19, 5*20), and then the factor 5 in these 4 numbers has been calculated again.