https://www.acmicpc.net/problem/1676
1676번: 팩토리얼 0의 개수
N!에서 뒤에서부터 처음 0이 아닌 숫자가 나올 때까지 0의 개수를 구하는 프로그램을 작성하시오.
www.acmicpc.net
import sys
from math import factorial
input = sys.stdin.readline
N = int(input())
fn=factorial(N)
count=0
while(fn %10 ==0):
if fn% 10 !=0:
break
fn=fn // 10
count+=1
print(count)
n = int(input())
def five_count(n):
cnt = 0
while n != 0:
n //= 5
cnt += n
return cnt
print(five_count(n))
후자는 인터넷에서 본 꽤나 똑똑한 방법. 뭘 써도 상관없긴하다.
'취준 > 백준' 카테고리의 다른 글
2178 - 파이썬 (0) | 2022.07.05 |
---|---|
2004 - 백준 (0) | 2022.05.11 |
9375 - 파이썬 (0) | 2022.05.09 |
11051 - 파이썬 (0) | 2022.05.06 |
3036 - 파이썬 (0) | 2022.05.06 |