N!

N!

Time Limit: 1000ms   Memory limit: 65536K  有疑問?點這裏^_^

題目描述

首先很感謝劉老師能給我這次機會給大家出題,希望大家做完題後能有所收穫,如果有任何問題還請海涵,畢竟出套題不容易……TAT
題目整體不難,大體是給我帶的大一新生出題的難度,所以請各位放心。
If you want to learn something from other people, remember, stay hunger.---shadow95 
Now, your first problem comes~ 
This task is very simple, please calculate how many zeros are there at the end of calculation of n!. 
For example, 15! = 1307674368000, so answer is 3.

輸入

 At the first line, there is a number T indicating the number of test cases. 
Then, following T lines, each line there is a number n (n<10^9).

輸出

For each case, output the case number and answer in one line. 

示例輸入

3
5
100
1024

示例輸出

Case #1: 1
Case #2: 24
Case #3: 253

提示

 

來源

 HDU shadow95

示例程序

  1. #include<stdio.h>  
  2. #include<string.h>  
  3.   
  4. int fun(int n)  
  5. {  
  6.     int sum=0;  
  7.     while(n)  
  8.     {  
  9.         n=n/5;  
  10.         sum+=n;  
  11.     }  
  12.     return sum;  
  13. }  
  14.   
  15. int main()  
  16. {  
  17.     int t, T, n;  
  18.     scanf("%d", &T);  
  19.     for(int t=1;t<=T;t++)  
  20.     {  
  21.         scanf("%d", &n);  
  22.         int re=fun(n);  
  23.         printf("Case #%d: %d\n", t, re);  
  24.     }  
  25.     return 0;  
  26. }   
  27.   

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章