카테고리 없음
[백준] 팩토리얼 0의 개수
RUBY_루비
2020. 9. 30. 23:59
출처:: www.acmicpc.net/problem/1676
분류::
1. 문제 이해 및 해결과정
2. 풀이방법
#팩토리얼 0의 개수
#https://www.acmicpc.net/problem/1676
import sys
sys.stdin = open("input.txt","r")
n=int(input())
def fact(n):
factorial=1
if n==0 or n==1:
return 1
else:
for i in range(1,n+1):
factorial=i*factorial
return factorial
num=fact(n)
num=list(str(num))
cnt=0
for i in range(len(num)-1,-1,-1):
if num[i]!='0':
break
else:
cnt+=1
print(cnt)
3. 오답원인
1. n이 500이라면 시간초과
#팩토리얼 0의 개수
#https://www.acmicpc.net/problem/1676
import sys
sys.stdin = open("input.txt","r")
n=int(input())
def fact(n):
if n==0 or n==1:
return 1
else:
return n*fact(n-1)
num=fact(n)
cnt=0
while num>0:
if num%10==0:
cnt+=1
num/=10
else:
break
print(cnt)
4. 알게된 점