본문 바로가기

코딩

[Python] 백준 #1676. 팩토리얼 0의 개수

https://www.acmicpc.net/problem/1676

 

1676번: 팩토리얼 0의 개수

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

www.acmicpc.net

 

# 1676 - Python 3

import sys

input = sys.stdin.readline

def factorial(n):               # factorial 함수
    answer = 1

    if n == 1:
        return answer
    elif n == 0:
        return answer
    else:
        while n != 1:
            answer *= n
            n -= 1
        
        return answer

n = factorial(int(input()))

cnt = 0

while n % 10 == 0:
    cnt += 1
    n //= 10

print(cnt)

'코딩' 카테고리의 다른 글

[Python] 백준 #1158. 요세푸스 문제  (0) 2023.09.22
[Python] 백준 #1026. 보물  (0) 2023.09.22
[Python] 백준 #1769. 3의 배수  (0) 2023.09.21
[Python] 백준 #1312. 소수  (0) 2023.09.21
[Python] 백준 #1357. 뒤집힌 덧셈  (0) 2023.09.21