1003 阶乘后面0的数量
生活随笔
收集整理的這篇文章主要介紹了
1003 阶乘后面0的数量
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1003 階乘后面0的數量
基準時間限制:1 秒 空間限制:131072 KB n的階乘后面有多少個0? 6的階乘 = 1*2*3*4*5*6 = 720,720后面有1個0。 Input 一個數N(1?<=?N?<=?10^9) Output 輸出0的數量 Input示例 5 Output示例 1 //統計2和5個數就好了; #include <cstdio> typedef long long LL; LL min(LL a, LL b) {return a<b? a:b; } LL cnt_0(LL n) {LL sum=0;int p =10;for(int i=1; i<=10; i++){sum+= n/p;p*=10;}return sum; } LL cnt_2(LL n) {LL cnt=0;while(n){cnt+= n/2;n/=2;}return cnt; } LL cnt_5(LL n) {LL cnt=0;while(n){cnt+= n/5;n/= 5;}return cnt; } int main() {LL n;while(scanf("%lld", &n) != EOF){printf("%lld\n", min(cnt_2(n), cnt_5(n)));}return 0; }?
轉載于:https://www.cnblogs.com/ceal/p/5469077.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的1003 阶乘后面0的数量的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python全栈开发之3、数据类型set
- 下一篇: (转)数组循环右移