백준 코드 공부/파이썬

백준 1676 : 팩토리얼 0의 개수 (Python)

GUuu9 2022. 4. 8. 21:54

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

 

1676번: 팩토리얼 0의 개수

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

www.acmicpc.net


문제

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

입력

첫째 줄에 N이 주어진다. (0 ≤ N ≤ 500)

출력

첫째 줄에 구한 0의 개수를 출력한다.

예제 입력 1 복사

10

예제 출력 1 복사

2

예제 입력 2 복사

3

예제 출력 2 복사

0

출처

 


from math import factorial

N = int(input())
factorial_str = str(factorial(N))
zeroCount = 0
for i in factorial_str[::-1]:
    if i == '0':
        zeroCount += 1
    else:
        break

print(zeroCount)

 

 


Git Hub

https://github.com/GUuu9/BaekJoon-Study/blob/main/1676.py

 

GitHub - GUuu9/BaekJoon-Study

Contribute to GUuu9/BaekJoon-Study development by creating an account on GitHub.

github.com