hdu 1124 Factorial (快速求n!末尾0的个数)
来源:互联网 发布:下载百度壁纸软件 编辑:程序博客网 时间:2024/05/22 09:39
思路:f(n)表示n!的末尾0的个数,则
f(n) = n/5 + f(n/5) n >= 5
f(n) = 0; n < 5
证明:点击
代码:
#include <iostream>#include <stdio.h>#include <string.h>#include <math.h>#include <stdlib.h>#include <map>#include <set>#include <vector>#include <stack>#include <queue>#include <algorithm>using namespace std;#define mst(a,b) memset(a,b,sizeof(a))#define eps 10e-8const int MAX_ = 10010;const int N = 100010;const int INF = 0x7fffffff;int a[MAX_];int find(int n){ if(n < 5)return 0; return n/5 + find(n/5);}int main(){int n, T;scanf("%d", &T);while(T--){ scanf("%d", &n); int ans = find(n); printf("%d\n", ans); }return 0;}
0 0
- hdu 1124 Factorial (快速求n!末尾0的个数)
- 快速求N!末尾零的个数
- leetcode解题之172# Factorial Trailing Zeroes Java版 (求n的阶乘末尾0的个数)
- Factorial Trailing Zeroes N!末尾0的个数
- 172. Factorial Trailing Zeroes计算n!末尾0的个数
- 数学基础:HUD1124-Factorial(N!末尾0的个数)
- hdu 1124(数论,求末尾0的个数)
- 求N!的末尾0的个数
- 求n!末尾0的个数
- 求n!末尾0的个数
- 求n!末尾0的个数
- 求阶乘N!末尾0的个数
- 求N!末尾0的个数
- 求n!末尾0的个数
- 求N!末尾0的个数
- 求 N!末尾0的个数
- 求阶乘N!末尾0的个数
- 求n!末尾0的个数
- COC Like 游戏中的寻路算法
- -贪多嚼不烂
- 图的存储结构(1):数组表示法
- Eclipse安装Tomcat插件失败问题
- Oracle Database 11g Release 2 RAC On Oracle Linux 5.8 Using VirtualBox
- hdu 1124 Factorial (快速求n!末尾0的个数)
- 我的java学习日记(19)
- oracle中的相关子查询(correlated subqueries)
- vs2012编译protobuf
- RAC安装遇到的问题处理
- Android屏幕大小适配问题解决
- hdu 1241 Oil Deposits (连通块的个数)
- Servlet——开发细节+ServletConfig对象
- object引用Foundation头文件