Zoj
2022 factorial
The first question of self a in the IDC room ~
Find the number of consecutive zeros on the tail of the given factorial;
Train of Thought: high requirements on efficiency, so there is no need to doubt that it is a reference to others' ideas. The most intolerable way of thinking: Calculate the factorial and then count ~ The maximum number is 10. How can this problem be solved ~ The most intolerable way of thinking: I found that 0 is multiplied by 5, but for example, 25 has 2 5, and 2 0 will be obtained. The most intolerable way of thinking: count 1 ~ N The number of five of these numbers; the idea is that each five numbers has a 5, and each five shows another 5, so we only need to accumulate N/5 + (n/5/5) + (n/5/5/5) + ...... That's all ...... Khan, another question I'm stupid about ......
Code:
#include<stdio.h>int main(){int i,n,sum,T;scanf("%d",&T);for(i = 1;i<=T;i++){scanf("%d",&n);sum = 0;while(n/5>0){sum = sum+n/5;n = n/5;}printf("%d\n",sum);}return 0;}