일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
- 알고리즘
- 가치규범의 공공외교
- 풀이
- B-tree
- 이항계수
- CSS
- 백준 1246번
- html
- 풍선터뜨리기
- 1141번
- 챗봇
- 백준
- 0의 개수
- 파이썬
- 백준 11050번
- 1
- 연산자 문제
- 백준 1487번
- Python
- hashing
- 실버
- BTREE
- 백준 14501번
- 해싱
- 문제 풀이
- 주창형 공공외교
- 해설
- DP 알고리즘
- 한반도평화와공공외교
- N과 M
- Today
- Total
목록0의 개수 (2)
SunFly의 코딩 및 정보 블로그

풀이 팩토리얼을 사용하면 재귀함수를 사용하게 되어서 시간초과 가 일어난다. import sys input = sys.stdin.readline def factorial(x): res = 1 for i in range(1, x+1): res *= i return res def cnt_zero(x): cnt = 0 for i in x: if i == '0': cnt += 1 else: break return cnt n, m = map(int, input().split()) result = str(factorial(n) // (factorial(n-m) * factorial(m))) result = reversed(result) cnt = cnt_zero(result) print(cnt) 따라서 다시 생각해보..
문제 N!에서 뒤에서부터 처음 0이 아닌 숫자가 나올 때까지 0의 개수를 구하는 프로그램을 작성하시오. 입력 첫째 줄에 N이 주어진다. (0 ≤ N ≤ 500) 출력 첫째 줄에 구한 0의 개수를 출력한다. 풀이 import sys def factorial(x): # 팩토리얼 res = 1 for i in range(1, x+1): res *= i return res input = sys.stdin.readline N = int(input()) N_f = factorial(N) N_f = list(str(N_f)) N_f = reversed(N_f) # 리스트 거꾸로 cnt = 0 for i in N_f: if i == '0': # 만약 0이랑 같다면 cnt가 +1 cnt += 1 else: break p..