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

코뉴·2021년 8월 11일
0

백준🍳

목록 보기
47/149

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

🥚문제


🥚입력/출력


🍳코드

ver. 01 (정-직)

from sys import stdin
input = stdin.readline

dp = [None]*501
# 0! = 1
dp[0] = 1

# N! 구하기
n = int(input())
for i in range(n+1):
    if i > 0:
        dp[i] = dp[i-1] * i

# N!에서 뒤에서 처음 0이 아닌 숫자가 나올 때까지 0의 개수
n_fact = dp[n]
count = 0
while n_fact > 0:
    # 10으로 나누었을 때 나머지가 0이 아니면
    if n_fact % 10 != 0:
        break

    # 10으로 나누었을 때 나머지가 0이면
    count += 1
    n_fact = n_fact//10

print(count)

ver. 02 (수학)

from sys import stdin
input = stdin.readline

n = int(input())

multiple_of_5 = 5
count = 0

while multiple_of_5 <= n:
    count += n//multiple_of_5
    multiple_of_5 *= 5

print(count)

🧂아이디어

profile
코뉴의 도딩기록

0개의 댓글