알고리즘 문제

[C/C++ 백준 1676번] 팩토리얼 0의 개수 (Silver 3)

새파란 공대생 2020. 9. 14. 02:05

www.acmicpc.net/problem/1676

 

1676번: 팩토리얼 0의 개수

N!에서 뒤에서부터 처음 0이 아닌 숫자가 나올 때까지 0의 개수를 구하는 프로그램을 작성하시오.

www.acmicpc.net

5의 개수만 세어주자.

 

#include <cstdio>
int main(void){
	int N;
	scanf("%d", &N);
	int five = 5, ans = 0;
	while(five<N){
		ans += N/five;
		five *= 5;
	}
	printf("%d", ans);
}