출처 | 팩토리얼 0의 개수 [백준 1676]
N!에서 뒤에서부터 처음 0이 아닌 숫자가 나올 때까지 0의 개수를 구하는 프로그램을 작성하시오.
첫째 줄에 N이 주어진다. (0 ≤ N ≤ 500)
첫째 줄에 구한 0의 개수를 출력한다.
def factorial(N):
ans = 1
for i in range(1, N+1):
ans *= i
return ans
N = int(input())
string = str(factorial(N))
count = 0
for i in range(len(string) - 1, 0, -1):
if string[i] == '0':
count += 1
else:
break
print(count)