zoj 2022||poj 1401 Factorial(阶乘)
来源:互联网 发布:程序员很难找女朋友吗 编辑:程序博客网 时间:2024/04/30 01:26
题意:
求阶乘N!的末尾的零的个数。
分析:
首先大数肯定是不用想了,题目给的时间只有2s...
那么怎么办呢?偶转载的一篇文章里有讲过。http://blog.csdn.net/cqlf__/article/details/6974902
形成末尾0,就是因子5的数量,一开始我从5~N找起,花了一番功夫把26/5==0类似这种情况处理掉,并且也能出结果了,卡B了。
超时,输入1000000000看看发现等了很久才出结果,不超才怪。
然后继续看了下文章,发现了更好的算法,直接N/5,ym.
/*#include <stdio.h>int main(){long T,N,num;long j,i;scanf("%d",&T);while(T--){num=0;scanf("%d",&N);for(j=5;j<=N;j++){i=j;while(i){if(i%5!=0) break;if(i%5==0) num++;i=i/5;}}printf("%d\n",num);}return 0;}*/#include <stdio.h>int main(){long cnt,T,N;scanf("%d",&T);while(T--){cnt=0;scanf("%d",&N);while(N){N/=5;cnt+=N;}printf("%d\n",cnt);}}
- zoj 2022||poj 1401 Factorial(阶乘)
- POJ 1401 && ZOJ 2202 Factorial 阶乘N!的末尾零的个数
- POJ 1401 Factorial 阶乘0的数量 .
- 【POJ】1401 - Factorial(阶乘最后0的个数)
- zoj 2022 Factorial
- ZOJ 2022 Factorial
- ZOJ 2022 Factorial
- zoj 2022 Factorial}
- Factorial 阶乘
- factorial,阶乘
- ZOJ Problem Set - 2022||Factorial
- POJ 1401:Factorial 求一个数阶乘的末尾0的个数
- poj 1401 Factorial
- POJ 1401 Factorial
- POJ 1401 Factorial
- poj 1401 Factorial
- poj 1401 Factorial
- poj 1401 Factorial
- linux下查看文件编码及修改编码
- Weak Alias
- 信号量的实现和应用
- Spring中获得数据库的自增主键值
- 在Magento产品管理中添加额外信息
- zoj 2022||poj 1401 Factorial(阶乘)
- 匿名函数的两个经典错误
- 如何去掉FormView的滚动条
- spring+jasperReport 常见异常
- 认识User-Agent
- 通过canvas和paint工具并继承view类自定义控件举例
- exchange server 2003搭建及外网收发邮件
- 《软件架构评估》读书笔记
- PHP获取用户Ip