일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Bellman-Ford
- 백트래킹
- 함밥
- 장고
- SQL
- django
- 백준
- Kruskal
- 최소스패닝트리
- DFS
- 알고리즘
- 데이터베이스
- 실습
- codetree
- MyPlaylist
- B대면노래방
- programmers
- 소프트웨어공학
- BFS
- 파이썬
- 종합설계
- 모각코
- Planned
- 그리디알고리즘
- 프로그래머스
- 마라마라빔
- minimum spanning tree
- 코드트리
- 동적계획법
- DP
Archives
- Today
- Total
Leta Learns
[Python] 백준 1676번 - 팩토리얼 0의 개수 본문
문제 https://www.acmicpc.net/problem/1676
import sys
input = sys.stdin.readline
def factorial(n):
fac = 1
for i in range(1, n+1):
fac *= i
return fac
n = int(input())
ans = factorial(n)
strans = str(ans)
cnt = 0
for i in range(len(strans)-1, -1, -1):
if strans[i] == '0':
cnt += 1
else:
break
print(cnt)
#2022-08-06 (코드 수정)
모각코 글에 어떤 분이 math 모듈에 factorial함수가 있다고 알려주셔서 코드를 수정했다! 다시 한 번 감사합니다.
#math 모듈 factorial 함수 사용한 코드
import sys, math
input = sys.stdin.readline
n = int(input())
ans = math.factorial(n)
strans = str(ans)
cnt = 0
for i in range(len(strans)-1, -1, -1):
if strans[i] == '0':
cnt += 1
else:
break
print(cnt)
'Coding > 백준' 카테고리의 다른 글
[Python] 백준 9375번 - 패션왕 신해빈 (0) | 2022.08.06 |
---|---|
[Python] 백준 1541번 - 잃어버린 괄호 (0) | 2022.08.03 |
[Python] 백준 1654번 - 랜선 자르기 (0) | 2022.07.27 |
[Python] 백준 1436번 - 영화감독 숌 (0) | 2022.07.23 |
[Python] 백준 1463번 - 1로 만들기 (0) | 2022.07.23 |
Comments