在学校的oj上做了一道题,答案正确,但是一直超时,搞不懂,不过还是把代码贴出来吧
Problem description |
从输入文件中读取一个数n,求出n!中末尾0的个数。 |
Input |
输入包含若干组数据。第一行上有一个整数m,指明接下来的数字的个数。然后是m行,每一行包含一个确定的正整数n,1£n£1000000000。 |
Output |
对输入行中的每一个数据n,输出一行,其内容是n!中末尾0的个数。 |
Sample Input |
3 3 100 1024 |
Sample Output |
0 24 253 |
#include<stdio.h>
int main(void) {
int num,n,count,temp;
int i;
scanf("%d",&n);
while(n--) {
count = 0;
scanf("%d",&num);
for(i=1; i<=num; i++) {
temp = i;
while((temp % 5 == 0) && temp >0) {
count++;
temp = temp / 5;
}
}
printf("%d\n",count);
}
return 0;
}