【杭电】[1124]Factorial

文章字数:143

问题描述

问题分析

从宇神处获得的一个小公式
求N!末尾有几个0

核心代码:

1
2
3
4
5
int cnt=0;
		while(n) {
			cnt+=n/5;
			n/=5;
		}

也是找了一个杭电上的题目
……话说题目好复杂啊
但是大意很简单
没什么坑

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#include<stdio.h>
int main() {
	int T;
	scanf("%d",&T);
	while(T--) {
		int n;
		scanf("%d",&n);
		int cnt=0;
		while(n) {
			cnt+=n/5;
			n/=5;
		}
		printf("%d\n",cnt);
	}
	return 0;
}

题目地址:【杭电】[1124]Factorial

该内容采用 CC BY-NC-SA 4.0 许可协议。

如果对您有帮助或存在意见建议,欢迎在下方评论交流。

加载中...