[๋ฐฑ์ค€/python] 1676๋ฒˆ : ํŒฉํ† ๋ฆฌ์–ผ 0์˜ ๊ฐœ์ˆ˜

2021. 8. 18. 00:29

๋ฌธ์ œ

N!์—์„œ ๋’ค์—์„œ๋ถ€ํ„ฐ ์ฒ˜์Œ 0์ด ์•„๋‹Œ ์ˆซ์ž๊ฐ€ ๋‚˜์˜ฌ ๋•Œ๊นŒ์ง€ 0์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— N์ด ์ฃผ์–ด์ง„๋‹ค. (0 ≤ N ≤ 500)

 

์ถœ๋ ฅ

์ฒซ์งธ ์ค„์— ๊ตฌํ•œ 0์˜ ๊ฐœ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

 

์ •๋‹ต

import sys
input = sys.stdin.readline

N = int(input())

if N == 0:
    print(0)

else:
    for i in range(N-1, 0, -1):
        N *= i

    for idx, n in enumerate("".join(reversed(str(N)))):
        if n != '0':
            print(idx)
            break

์˜ˆ๋ฅผ ๋“ค์–ด ์ž…๋ ฅ๊ฐ’์ด 10์ผ ๋•Œ

10! = 3628800์€ ๋’ค์—์„œ๋ถ€ํ„ฐ ์„ธ๋ฒˆ์งธ ์ˆซ์ž์— 0์ด ์•„๋‹Œ ์ˆซ์ž 8์ด ์˜ค๋ฏ€๋กœ

์ถœ๋ ฅ๊ฐ’์€ 0์˜ ๊ฐœ์ˆ˜์ธ 2๊ฐ€ ๋˜์–ด์•ผํ•œ๋‹ค.

 

0!์€ 1์ด๋ฏ€๋กœ ์ถœ๋ ฅ๊ฐ’์ด 0์ด ๋˜์–ด์•ผํ•œ๋‹ค.

728x90

BELATED ARTICLES

more