python | 팩토리얼 0의 개수 [백준 1676]

나경호·2022년 4월 9일
0

알고리즘 Algorithm

목록 보기
15/106
post-thumbnail

팩토리얼 0의 개수

출처 | 팩토리얼 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)

출처

알고리즘 분류

profile
기억창고👩‍🌾

0개의 댓글