阶乘 hdu 1124 (Factorial)
来源:互联网 发布:matlab矩阵逻辑运算 编辑:程序博客网 时间:2024/04/28 01:39
Factorial
Problem Description
For example, they defined the function Z. For any positive integer N, Z(N) is the number of zeros at the end of the decimal form of number N!. They noticed that this function never decreases. If we have two numbers N1<N2, then Z(N1) <= Z(N2). It is because we can never "lose" any trailing zero by multiplying by any positive number. We can only get new and new zeros. The function Z is very interesting, so we need a computer program that can determine its value efficiently.
Input
There is a single positive integer T on the first line of input. It stands for the number of numbers to follow. Then there is T lines, each containing exactly one positive integer number N, 1 <= N <= 1000000000.
Output
For every number N, output a single line containing the single non-negative integer Z(N).
Sample Input
63601001024234568735373
Sample Output
0142425358612183837
题意:给出n,求n的阶乘的末尾有多少0.
题解:由算数基本定理可:N!可划分为 质因数相乘的形式 N!=2^a*3^b*5^c*7^d........
因为只有2*5 才会出现 0 又因为2的数量肯定比5的多 所以计算阶乘中5的数量就可以得到该阶乘后有几个0。
50/5=10 10/5=2 所以50!后有10+2=12个0。
#include<cstdio>#include<cmath>using namespace std;int cnt;int solve(int n){cnt=0;while (n){cnt+=n/5;n/=5;}return cnt;}int main(){int n, t;scanf ("%d",&t);while (t--){scanf ("%d",&n);solve(n);printf ("%d\n",cnt);}return 0;}
0 0
- 阶乘 hdu 1124 (Factorial)
- HDU 1124 Factorial&&nyoj 84 阶乘的 0【数学】
- HDU 1124 Factorial (數論)
- HDU 1124 Factorial(数论)
- HDU 1124 Factorial(数论)
- Factorial 阶乘
- factorial,阶乘
- hdu 1124 Factorial 数论,就是求一个数的阶乘的结果末尾有多少0.
- hdu 1124 Factorial(末尾0)
- Factorial hdu 1124
- HDU 1124 Factorial
- HDU 1124 Factorial
- HDU 1124 Factorial
- HDU:1124 Factorial
- hdu 1124 Factorial
- HDU 1124 Factorial
- hdu 1124 Factorial
- HDU 1124 Factorial
- Vijos P1117数的划分
- XML文件解析
- java第一周
- React Native的WebStorm基本设置
- Ubiquitous Religions ---并查集入门
- 阶乘 hdu 1124 (Factorial)
- (四十一)、设计模式
- chromium中HTTP网络资源的加载过程
- xml解析pull
- dll工程中如何生成lib文件
- android zipalign
- java 时间格式转换
- ubuntu下不能识别安卓设备
- JAVA简单Factory模式