728x90
반응형
문제 출처:https://www.acmicpc.net/problem/1676
1676번: 팩토리얼 0의 개수
N!에서 뒤에서부터 처음 0이 아닌 숫자가 나올 때까지 0의 개수를 구하는 프로그램을 작성하시오.
www.acmicpc.net
풀이:
import sys
input = sys.stdin.readline
import math
# fac_a = math.factorial(int(input()))
# list_fac_a = list(map(int,str(fac_a)))
list_fac_a = list(map(int,str(math.factorial(int(input()))))) # 위에 두줄을 한줄로 표헌
list_fac_a.reverse()
res = 0
for i in list_fac_a:
if i == 0:
res += 1
if i != 0:
break
print(res)
받은 숫자를 하나하나 자라서 리스트에 저장후 뒤에서부터 0이 아닌수가 나오는거니까 반대로 뒤집은후
포문을 돌려 0이 아닐때 포문을 탈출후 res를 출력한다.
반응형
댓글